我有一个混合应用程序,我已经覆盖了android Application类,如下所示:
public class ContainerApplication extends DaggerApplication
//and then
public abstract class DaggerApplication extends Application
{
public static DaggerApplication instance;
public void onCreate() {
super.onCreate();
instance = this;
}
}
//then in my main activity
public class MainActivity
extends Activity {
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
// this is a addModule method in my ContainerApplication class and the argument is some object which is not null;
ContainerApplication.instance.addModule(object);
}
}
// I get an stack trace in google play store that the ContainerApplication.instance is null;
// the stacktrace for the same is as below:
java.lang.RuntimeException: Unable to start activity ComponentInfo{ca.bell.selfserve.mybellmobile/com.pega.mobile.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.pega.mobile.DaggerApplication.addModule(java.lang.Object)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2947)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3008)
at android.app.ActivityThread.-wrap14(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1650)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6688)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.pega.mobile.DaggerApplication.addModule(java.lang.Object)' on a null object reference
at com.pega.mobile.MainActivity.onCreate(MainActivity.java:35)
at android.app.Activity.performCreate(Activity.java:6912)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2900)
我已经在Android清单文件中正确提供了类详细信息。此实现在大多数Android设备和模拟器上运行良好,但有一些设备,特别是三星设备,应用程序在{{1}崩溃} call,如下面的堆栈跟踪线所示:
ContainerApplication.instance.addModule()
此外,我的应用中没有启用multidex。
我已经浏览了很多关于Android 7.0崩溃的应用程序的帖子,但是大多数都有不同的原因而不是我在堆栈跟踪中得到的。
我的清单文件如下:
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.pega.mobile.DaggerApplication.addModule(java.lang.Object)' on a null object reference
这也可能是操作系统问题吗?
非常感谢任何帮助。