I have an hybrid application where i have overridden android Application class as below:
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)
I have properly provided the class details in the Android manifest file.Also this implementation works fine on most of the android devices and emulators with 7.0 but with some of the devices, specifically with Samsung devices the app crashes on ContainerApplication.instance.addModule()
call, as can be seen in below stack trace line:
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.pega.mobile.DaggerApplication.addModule(java.lang.Object)' on a null object reference
Also there is no multidex enabled in my app.
I have gone through lot of posts about issues of app crashed on android 7.0, but most of them have different reasons and not what I am getting in stack trace.
Also my manifest file is as below:
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:versionCode="43" android:versionName="2.2.2" package="ca.bell.selfserve.mybellmobile.poc2">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>\
<uses-permission android:name="android.permission.SET_DEBUG_APP"/>
<uses-permission android:description="@string/wifi_state_desc" android:label="@string/wifi_state_label" android:name="android.permission.CHANGE_WIFI_STATE" android:protectionLevel="signature"/>
<uses-permission android:description="@string/wifi_state_desc" android:label="@string/wifi_state_label" android:name="android.permission.CHANGE_NETWORK_STATE" android:protectionLevel="signature"/>
<uses-permission android:name="android.permission.WRITE_SETTINGS" android:protectionLevel="signature"/>
<uses-permission android:description="@string/loc_permission_desc" android:label="@string/loc_permission_label" android:name="android.permission.ACCESS_COARSE_LOCATION" android:protectionLevel="dangerous"/>
<uses-permission android:description="@string/loc_permission_desc" android:label="@string/loc_permission_label" android:name="android.permission.ACCESS_FINE_LOCATION" android:protectionLevel="dangerous"/>
<application android:allowBackup="true" android:fullBackupContent="@xml/full_backup_content" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:name="com.pega.mobile.ContainerApplication" android:theme="@style/AppTheme" tools:ignore="UnusedAttribute">
<activity android:configChanges="orientation|screenSize|keyboardHidden" android:launchMode="singleTop" android:name="com.pega.mobile.MainActivity" android:screenOrientation="portrait" android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<provider android:authorities="ca.bell.selfserve.mybellmobile.fileProvider" android:exported="false" android:grantUriPermissions="true" android:name="android.support.v4.content.FileProvider">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths"/>
</provider>
</application>
</manifest>
Also can this be an OS issue?
Any help will be much appreciated.