例如,我有两个活动HomeScreen和PostListScreen。
步骤 1.从HomeScreen导航到PostListScreen。 2.最小化应用 3.进入系统设置,然后增加/减少字体。 4.再次打开应用程序
现在,我遇到了以下错误。
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.LinearLayout.setVisibility(int)' on a null object reference
at *package**activity*.isVisible(*activity*.java:505)
at *package**activity*.searchData(*activity*.java:487)
at *package**activity*$3.onTextChanged(*activity*.java:191)
at android.widget.TextView.sendOnTextChanged(TextView.java:9786)
at android.widget.TextView.setText(TextView.java:5765)
at android.widget.TextView.setText(TextView.java:5603)
at android.widget.EditText.setText(EditText.java:122)
at android.widget.TextView.setText(TextView.java:5560)
at android.widget.TextView.onRestoreInstanceState(TextView.java:5428)
at android.view.View.dispatchRestoreInstanceState(View.java:18751)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:3831)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:3831)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:3831)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:3831)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:3831)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:3831)
at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:3831)
at android.view.View.restoreHierarchyState(View.java:18729)
at com.android.internal.policy.PhoneWindow.restoreHierarchyState(PhoneWindow.java:2171)
at android.app.Activity.onRestoreInstanceState(Activity.java:1135)
at android.app.Activity.performRestoreInstanceState(Activity.java:1090)
at android.app.Instrumentation.callActivityOnRestoreInstanceState(Instrumentation.java:1338)
at android.app.ActivityThread.handleStartActivity(ActivityThread.java:3077)
at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:180)
at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:165)
at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:142)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1906)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6863)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:537)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
因此,基本上所有引用[LinearLayout,RecyclerView
e.t.c]的值都为 null 。
为此,我已经在google / StackOverflow / git等上花费了数小时,但无法为此找到解决方案。
应用配置
compileSdkVersion 27
minSdkVersion 19
targetSdkVersion 27
multiDexEnabled true