Application error after receiving a phone call

After I either received a phone call or make one (and other undocumented interrupts), my application receives a NullPointerException when my activity resumes. Can someone explain to me where it is and / or how to fix it? When my activity resumes, it calls the createCreate function and tries to execute something that is null after resuming. How to prevent onCreate () function call?

My activity stops when I press the call button, because when I try to debug this error, the debugger is turned off.

EDIT:

So, how do I handle a process killed → onCreate ()? I have actions A → B → C → D, and I press all the way to A, no problem. But if I run another program or another program comes to the fore, D crashes, then C crashes, then B crashes, then A crashes!

EDIT:

I solved B, C, D crash. This was because the class in which I stored the static variables was destroyed to free up resources, and my actions received null variables.

But when I get back to A, I get a classCastException:

08-13 16:52:10.456: ERROR/AndroidRuntime(6048): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.bookcessed.booksearch/com.bookcessed.booksearch.activities.ChooseProviderActivity}: java.lang.ClassCastException: android.view.AbsSavedState$1
08-13 16:52:10.456: ERROR/AndroidRuntime(6048):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
08-13 16:52:10.456: ERROR/AndroidRuntime(6048):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
08-13 16:52:10.456: ERROR/AndroidRuntime(6048):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
08-13 16:52:10.456: ERROR/AndroidRuntime(6048):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
08-13 16:52:10.456: ERROR/AndroidRuntime(6048):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-13 16:52:10.456: ERROR/AndroidRuntime(6048):     at android.os.Looper.loop(Looper.java:123)
08-13 16:52:10.456: ERROR/AndroidRuntime(6048):     at android.app.ActivityThread.main(ActivityThread.java:4627)
08-13 16:52:10.456: ERROR/AndroidRuntime(6048):     at java.lang.reflect.Method.invokeNative(Native Method)
08-13 16:52:10.456: ERROR/AndroidRuntime(6048):     at java.lang.reflect.Method.invoke(Method.java:521)
08-13 16:52:10.456: ERROR/AndroidRuntime(6048):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
08-13 16:52:10.456: ERROR/AndroidRuntime(6048):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
08-13 16:52:10.456: ERROR/AndroidRuntime(6048):     at dalvik.system.NativeStart.main(Native Method)
08-13 16:52:10.456: ERROR/AndroidRuntime(6048): Caused by: java.lang.ClassCastException: android.view.AbsSavedState$1
08-13 16:52:10.456: ERROR/AndroidRuntime(6048):     at android.widget.ProgressBar.onRestoreInstanceState(ProgressBar.java:944)
08-13 16:52:10.456: ERROR/AndroidRuntime(6048):     at android.view.View.dispatchRestoreInstanceState(View.java:6138)
08-13 16:52:10.456: ERROR/AndroidRuntime(6048):     at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:1209)
08-13 16:52:10.456: ERROR/AndroidRuntime(6048):     at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:1209)
08-13 16:52:10.456: ERROR/AndroidRuntime(6048):     at android.view.View.restoreHierarchyState(View.java:6117)
08-13 16:52:10.456: ERROR/AndroidRuntime(6048):     at com.android.internal.policy.impl.PhoneWindow.restoreHierarchyState(PhoneWindow.java:1466)
08-13 16:52:10.456: ERROR/AndroidRuntime(6048):     at android.app.Activity.onRestoreInstanceState(Activity.java:843)
08-13 16:52:10.456: ERROR/AndroidRuntime(6048):     at android.app.Activity.performRestoreInstanceState(Activity.java:815)
08-13 16:52:10.456: ERROR/AndroidRuntime(6048):     at android.app.Instrumentation.callActivityOnRestoreInstanceState(Instrumentation.java:1096)
08-13 16:52:10.456: ERROR/AndroidRuntime(6048):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2641)
08-13 16:52:10.456: ERROR/AndroidRuntime(6048):     ... 11 more

Here is my onCreate ():

super.onCreate(savedInstanceState);
        tempLayout = new RelativeLayout(ChooseProviderActivity.this);
        ProgressBar tempProgress = new ProgressBar(ChooseProviderActivity.this);
        tempProgress.setIndeterminate(true);
        tempProgress.setId(1); //I suspect this is the problem
        RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
                RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
        lp.addRule(RelativeLayout.CENTER_IN_PARENT);
        tempLayout.addView(tempProgress, lp);
        setContentView(tempLayout);

This is where I think the problem lies:

tempProgress.setId(1); //I suspect this is the problem
+3
source share
7 answers

Views, . ,

ProgressBar tempProgress = new ProgressBar(ChooseProviderActivity.this);
tempProgress.setIndeterminate(true);
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
                RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
lp.addRule(RelativeLayout.CENTER_IN_PARENT);
tempLayout.addView(tempProgress, lp);
setContentView(tempLayout);

ID XML , , R.java . ! . Edit!

, ID . RelativeLayout.LayoutParams.addRule(int, int), .

END EDIT

...

LinearLayout ll = new LinearLayout(SomeClass.this);
ll.setOrientation(VERTICAL);
TextView tv = new TextView(SomeClass.this);
EditText et = new EditText(SomeClass.this);
ll.add(tv);
ll.add(et);

textView EditText. ...

ll.add(et);
ll.add(tv);

EditText ABOVE TextView. ID , .

+1

, , os .  alt text

+2

- , onCreate. / , .

+1

, , Android , .

+1

- . , .

+1

, . logcat adb log.v, . , .

? ? -, .

0

.getStoredStaticVariable() .saveStoredStaticVariable(), , null, , , , .

EDIT: . ClassCastException()

tempProgress.setId(1);

, :

tempProgress.setId(6346346);
0
source

Source: https://habr.com/ru/post/1759572/


All Articles