开发者

Application crashed after either receive a phone call or such interruptions

After I either receive a phone call or make one, (and other undocumented interruptions) my application gets a NullPointerException when resuming my activity. Can any explain to me where it is and/or how to fix it?

I have written the code as shown below:

 @Override
    public void onCreate(开发者_StackOverflowBundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.displayActivity);
        new performBackgroundTask().execute();
  }

  @Override
  public void onDestroy()
  {
    listview1.setAdapter(null);
    super.onDestroy();
  }

  private class performBackgroundTask extends AsyncTask <Void, Void, Void>  
  {
           private ProgressDialog Dialog = new ProgressDialog(displayActivity.this);

           protected void onPreExecute()
           {
               Dialog.setMessage(getString(R.string.dialog_wait_message));
               Dialog.show();
           }

           protected void onPostExecute(Void unused)    
           {
               Dialog.dismiss();    
               // displaying all the fetched data
           }

           @Override
            protected Void doInBackground(Void... params) 
            {
                 // fetching data from web using HTTPGet method 
                return null;   
        }
  }

Logcat output is:

java.lang.RuntimeException: Unable to destroy activity {myApplication/MyApplication.displayActivity}: java.lang.NullPointerException at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3655) at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3673) at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3789) at android.app.ActivityThread.access$2400(ActivityThread.java:125) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2037) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:123) at android.app.ActivityThread.main(ActivityThread.java:4627) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:521) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.NullPointerException at MyApplication.displayActivity.onDestroy(displayActivity.java:74) at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3642)

now, pls help me to fix this problem, how do i handle phone call or SMS received or such kind of interruptions?


Step #1: Find line 74 of the displayActivity.java file.

Step #2: Fix whatever problem is on line 74.

Now, the stack trace suggests that line 74 is in onDestroy(). Assuming that the activity code you have listed above is from displayActivity, then line 74 must be:

listview1.setAdapter(null);

That means listview1 is null. You neither declare nor assign a value to this data member in the code you have listed above.


try setting a BP at the first line of onDestroy and validate vars/members to find which one is null

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜