我正在使用 Google Play Console 测试我的应用程序,然后再将其发布给公众,并且仅在运行 Android Nougat(7.1)的 Google Pixel 设备上启动时出现持续崩溃。其他所有设备都可以毫无问题地运行该应用程序,包括在 Android Oreo(8.0) 上运行的相同 Google Pixel。
日志显示以下信息:
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
完整的 MainActivity 来源:https ://pastebin.com/Ar5j2fEh
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);
}
}
}
我什至不知道从哪里开始调试。知道问题可能是什么吗?