这是我的报价。每当我删除以下行:mImageSwitcher_01.setImageResource(switchImages [0]);时,该应用程序都可以正常运行。目的是在启动应用程序后还原ImageSwitcher。保存状态信息通过共享首选项保存。
onCreateView上的公共视图(@NonNull LayoutInflater充气机,@ Nullable ViewGroup容器,@ Nullable Bundle savedInstanceState){
View view = inflater.inflate(R.layout.fragment_remote_control, container, false);
//initialize database
savedInstanceDB = FirebaseFirestore.getInstance();
//Initialize ON_OFF Buttons (ON Button 1 to 4 & OFF Button 1 to 4)
mButtonON_01 = view.findViewById(R.id.on_btn_01);
mButtonOFF_01 = view.findViewById(R.id.off_btn_01);
mButtonON_02 = view.findViewById(R.id.on_btn_02);
mButtonOFF_02 = view.findViewById(R.id.off_btn_02);
mButtonON_03 = view.findViewById(R.id.on_btn_03);
mButtonOFF_03 = view.findViewById(R.id.off_btn_03);
mButtonON_04 = view.findViewById(R.id.on_btn_04);
mButtonOFF_04 = view.findViewById(R.id.off_btn_04);
//Initialize ImageSwitchers 1 to 4
mImageSwitcher_01 = view.findViewById(R.id.image_switcher_01);
mImageSwitcher_02 = view.findViewById(R.id.image_switcher_02);
mImageSwitcher_03 = view.findViewById(R.id.image_switcher_03);
mImageSwitcher_04 = view.findViewById(R.id.image_switcher_04);
//Restore saved Imageswitcher instance for ImageSwitcher 1 to 4
if (savedInstanceState != null) {
int savedSwitchState_01 = savedInstanceState.getInt(KEY_IMAGE_SWITCHER_01);
mImageSwitcher_01.setImageResource(savedSwitchState_01);
int savedSwitchState_02 = savedInstanceState.getInt(KEY_IMAGE_SWITCHER_02);
mImageSwitcher_02.setImageResource(savedSwitchState_02);
int savedSwitchState_03 = savedInstanceState.getInt(KEY_IMAGE_SWITCHER_03);
mImageSwitcher_03.setImageResource(savedSwitchState_03);
int savedSwitchState_04 = savedInstanceState.getInt(KEY_IMAGE_SWITCHER_04);
mImageSwitcher_04.setImageResource(savedSwitchState_04);
} else if (loadSwitchStatus(SWITCH_ID_01, DOCUMENT_ID_01, IMAGE_INDEX_01) == 0 /*|| loadSwitchStatus(SWITCH_ID_01, DOCUMENT_ID_01, IMAGE_INDEX_01) == 1*/) {
/*image_id_01 = switchImages[loadSwitchStatus(SWITCH_ID_01, DOCUMENT_ID_01, IMAGE_INDEX_01)];*/
//Toast.makeText(mContext, Integer.toString(loadSwitchStatus(SWITCH_ID_01, DOCUMENT_ID_01, IMAGE_INDEX_01)), Toast.LENGTH_SHORT).show();
mImageSwitcher_01.setImageResource(switchImages[0]);
} else {
Toast.makeText(mContext, "Switches not Active", Toast.LENGTH_SHORT).show();
}
//Display selected image in ImageSwitcher 1 to 4
mImageSwitcher_01.setFactory(new ViewSwitcher.ViewFactory() {
@Override
public View makeView() {
ImageView mImageView = new ImageView(mContext.getApplicationContext());
mImageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
return mImageView;
}
});
mImageSwitcher_02.setFactory(new ViewSwitcher.ViewFactory() {
@Override
public View makeView() {
ImageView mImageView = new ImageView(mContext.getApplicationContext());
mImageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
return mImageView;
}
});
mImageSwitcher_03.setFactory(new ViewSwitcher.ViewFactory() {
@Override
public View makeView() {
ImageView mImageView = new ImageView(mContext.getApplicationContext());
mImageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
return mImageView;
}
});
mImageSwitcher_04.setFactory(new ViewSwitcher.ViewFactory() {
@Override
public View makeView() {
ImageView mImageView = new ImageView(mContext.getApplicationContext());
mImageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
return mImageView;
}
});
}
堆栈跟踪: 09-21 14:27:26.995 32097-32097 /? E / dalvikvm:>>>>>普通用户
za.co.nurontech.mrc [userId:0 | appId:10174] 09-21 14:27:27.265 32097-32097 / za.co.nurontech.mrc E / dalvikvm:找不到方法com.google.android.gms.internal引用的类'android.app.job.JobScheduler'。 zzcll.zzbax 09-21 14:27:27.265 32097-32097 / za.co.nurontech.mrc E / dalvikvm:找不到方法com.google.android.gms.internal引用的类'android.app.job.JobScheduler'。 zzcll.zzs 09-21 14:27:27.406 32097-32097 / za.co.nurontech.mrc E / dalvikvm:找不到从方法android.support.v4引用的类'android.support.v4.view.ViewCompat $ OnUnhandledKeyEventListenerWrapper'。 view.ViewCompat.addOnUnhandledKeyEventListener 09-21 14:27:27.406 32097-32097 / za.co.nurontech.mrc E / dalvikvm:找不到类``android.view.WindowInsets'',从方法android.support.v4.view.ViewCompat.dispatchApplyWindowInsets引用 09-21 14:27:27.426 32097-32097 / za.co.nurontech.mrc E / dalvikvm:找不到从方法android.support.v4.view.ViewCompat.onApplyWindowInsets引用的类'android.view.WindowInsets' 09-21 14:27:27.426 32097-32097 / za.co.nurontech.mrc E / dalvikvm:找不到从方法android.support.v4.view.ViewCompat引用的类'android.view.View $ OnUnhandledKeyEventListener'。 removeOnUnhandledKeyEventListener 09-21 14:27:27.436 32097-32097 / za.co.nurontech.mrc E / dalvikvm:找不到类'android.support.v4.view.ViewCompat $ 1',从方法android.support.v4.view引用.ViewCompat.setOnApplyWindowInsetsListener 09-21 14:27:27.456 32097-32097 / za.co.nurontech.mrc E / dalvikvm:找不到从方法android.support.v7.widget.AppCompatImageHelper引用的类'android.graphics.drawable.RippleDrawable'。 hasOverlappingRendering 09-21 14:27:28.587 32097-32097 / za.co.nurontech.mrc E / dalvikvm:找不到类``android.widget.ThemedSpinnerAdapter'',从方法android.support.v7.widget.AppCompatSpinner $ DropDownAdapter引用。 09-21 14:27:28.877 32097-32097 / za.co.nurontech.mrc E / ViewSystem:ViewRootImpl#2曲面无效。 09-21 14:27:28.957 32097-32097 / za.co.nurontech.mrc E / dalvikvm:找不到类``android.support.v4.widget.DrawerLayout $ 1'',从方法android.support.v4.widget引用.DrawerLayout。 09-21 14:27:28.967 32097-32097 / za.co.nurontech.mrc E / dalvikvm:找不到类android.view.WindowInsets,从方法android.support.v4.widget.DrawerLayout.onDraw中引用 09-21 14:27:28.967 32097-32097 / za.co.nurontech.mrc E / dalvikvm:找不到类android.view.WindowInsets,从方法android.support.v4.widget.DrawerLayout.onMeasure引用 09-21 14:27:28.967 32097-32097 / za.co.nurontech.mrc E / dalvikvm:找不到类android.view.WindowInsets,从方法android.support.v4.widget.DrawerLayout.onMeasure引用 09-21 14:27:29.137 32097-32097 / za.co.nurontech.mrc E / dalvikvm:找不到方法com.google.android.gms.org引用的类'javax.net.ssl.SNIServerName'。 conscrypt.Platform.getSniHostnameFromParams 09-21 14:27:29.137 32097-32097 / za.co.nurontech.mrc E / dalvikvm:找不到方法com.google.android.gms.org引用的类'javax.net.ssl.SNIHostName'。 conscrypt.Platform.setParametersSniHostname 09-21 14:27:29.137 32097-32097 / za.co.nurontech.mrc E / dalvikvm:找不到方法com.google.android.gms.org引用的类'javax.net.ssl.SNIHostName'。 conscrypt.Platform.setParametersSniHostname 09-21 14:27:29.147 32097-32097 / za.co.nurontech.mrc E / dalvikvm:找不到方法com.google引用的类“ com.google.android.gms.org.conscrypt.Java8ExtendedSSLSession”。 android.gms.org.conscrypt.Platform.wrapSSLSession 09-21 14:27:29.288 32097-32097 / za.co.nurontech.mrc E / AndroidRuntime:FATAL EXCEPTION:main 流程:za.co.nurontech.mrc,PID:32097 java.lang.RuntimeException:无法启动活动ComponentInfo {za.co.nurontech.mrc / za.co.nurontech.mrc.ControlActivity}:java.lang.NullPointerException 在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2412) 在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2470) 在android.app.ActivityThread.access $ 900(ActivityThread.java:174) 在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1307) 在android.os.Handler.dispatchMessage(Handler.java:102) 在android.os.Looper.loop(Looper.java:146) 在android.app.ActivityThread.main(ActivityThread.java:5593) 在java.lang.reflect.Method.invokeNative(本机方法) 在java.lang.reflect.Method.invoke(Method.java:515) 在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1283) 在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099) 在dalvik.system.NativeStart.main(本机方法) 造成原因:java.lang.NullPointerException 在android.widget.ImageSwitcher.setImageResource(ImageSwitcher.java:41) 在za.co.nurontech.mrc.RemoteControlFragment.onCreateView(RemoteControlFragment.java:128) 在android.support.v4.app.Fragment.performCreateView(Fragment.java:2435) 在android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1460) 在android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1784) 在android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1852) 在android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:802) 在android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2625) 在android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2411) 在android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2366) 在android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2273) 在android.support.v4.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3273) 在android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:3229) 在android.support.v4.app.FragmentController.dispatchActivityCreated(FragmentController.java:201) 在android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:610) 在android.support.v7.app.AppCompatActivity.onStart(AppCompatActivity.java:178) 在android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1177) 在android.app.Activity.performStart(Activity.java:5468) 在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2385) 在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2470) 在android.app.ActivityThread.access $ 900(ActivityThread.java:174) 在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1307) 在android.os.Handler.dispatchMessage(Handler.java:102) 在android.os.Looper.loop(Looper.java:146) 在android.app.ActivityThread.main(ActivityThread.java:5593) 在java.lang.reflect.Method.invokeNative(本机方法) 在java.lang.reflect.Method.invoke(Method.java:515) 在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1283) 在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099) 在dalvik.system.NativeStart.main(本机方法)