I'm using Google Play Console to test my app before releasing it to the public and I'm getting a consistent crash on startup only on Google Pixel devices running on Android Nougat(7.1). Every other device runs the app without problems, including the same Google Pixel running on Android Oreo(8.0).
The log shows the following info:
D/AndroidRuntime(8360): Shutting down VM 11-15 13:14:46.176:
D/AndroidRuntime(8360): --------- beginning of crash
11-15 13:14:46.176: E/AndroidRuntime(8360): FATAL EXCEPTION: main
11-15 13:14:46.176: E/AndroidRuntime(8360): Process: com.systemallica.gallery, PID: 8360
11-15 13:14:46.176: E/AndroidRuntime(8360): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.systemallica.gallery/com.systemallica.gallery.MainActivity}: java.lang.NullPointerException: Attempt to get length of null array
11-15 13:14:46.176: E/AndroidRuntime(8360): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2665)
11-15 13:14:46.176: E/AndroidRuntime(8360): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
11-15 13:14:46.176: E/AndroidRuntime(8360): at android.app.ActivityThread.-wrap12(ActivityThread.java)
11-15 13:14:46.176: E/AndroidRuntime(8360): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
11-15 13:14:46.176: E/AndroidRuntime(8360): at android.os.Handler.dispatchMessage(Handler.java:102)
11-15 13:14:46.176: E/AndroidRuntime(8360): at android.os.Looper.loop(Looper.java:154)
11-15 13:14:46.176: E/AndroidRuntime(8360): at android.app.ActivityThread.main(ActivityThread.java:6119)
11-15 13:14:46.176: E/AndroidRuntime(8360): at java.lang.reflect.Method.invoke(Native Method)
11-15 13:14:46.176: E/AndroidRuntime(8360): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
11-15 13:14:46.176: E/AndroidRuntime(8360): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
11-15 13:14:46.176: E/AndroidRuntime(8360): Caused by: java.lang.NullPointerException: Attempt to get length of null array
11-15 13:14:46.176: E/AndroidRuntime(8360): at com.systemallica.gallery.MainActivity.b(Unknown Source)
11-15 13:14:46.176: E/AndroidRuntime(8360): at com.systemallica.gallery.MainActivity.onCreate(Unknown Source)
11-15 13:14:46.176: E/AndroidRuntime(8360): at android.app.Activity.performCreate(Activity.java:6679)
11-15 13:14:46.176: E/AndroidRuntime(8360): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
11-15 13:14:46.176: E/AndroidRuntime(8360): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
11-15 13:14:46.176: E/AndroidRuntime(8360): ... 9 more
11-15 13:14:46.181: W/ActivityManager(1002): Force finishing activity com.systemallica.gallery/.MainActivity
11-15 13:14:46.186: W/ActivityManager(1002): Force finishing activity com.systemallica.gallery/.MainActivity
Full MainActivity source: https://pastebin.com/Ar5j2fEh
The MainActivity onCreate:
public class MainActivity extends AppCompatActivity {
final int MY_PERMISSIONS_REQUEST_BOTH= 114;
@BindView(R.id.swipelayout) SwipeRefreshLayout swipeLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// Check for sdk >= 23
if (Build.VERSION.SDK_INT >= 23) {
// Check CAMERA and MEDIA permission
if (checkSelfPermission(Manifest.permission.CAMERA)!= PERMISSION_GRANTED ||
checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE)!= PERMISSION_GRANTED ||
checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)!= PERMISSION_GRANTED ){
requestPermissions(new String[]{
Manifest.permission.CAMERA,
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE},
MY_PERMISSIONS_REQUEST_BOTH);
// When permissions are granted
}else{
setFABListener();
loadFolders(columns);
}
}
// Set on swipe refresh listener
swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
startRefresh();
}
});
// Change navBar colour
if(android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){
int app_primary = ContextCompat.getColor(this, R.color.app_primary);
getWindow().setNavigationBarColor(app_primary);
}
}
}
I don't even know where to start debugging. Any idea of what the problem could be?