应用程序在接到电话或此类中断后崩溃

发布于 2024-09-30 09:05:53 字数 2412 浏览 1 评论 0原文

在我接到电话或拨打电话(以及其他未记录的中断)后,我的应用程序在恢复活动时收到 NullPointerException 。任何人都可以向我解释它在哪里和/或如何修复它吗?

我编写的代码如下所示:

 @Override
    public void onCreate(Bundle 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 输出为:

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

现在,请帮我解决这个问题,我如何处理收到的电话或短信或此类中断?

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(Bundle 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

烛影斜 2024-10-07 09:05:53

步骤#1:找到 displayActivity.java 文件的第 74 行。

步骤 #2:修复第 74 行中的任何问题。

现在,堆栈跟踪表明第 74 行位于 onDestroy() 中。假设您上面列出的活动代码来自 displayActivity,则第 74 行必须是:

listview1.setAdapter(null);

这意味着 listview1null。您既不需要在上面列出的代码中声明这个数据成员,也不需要为其赋值。

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.

×纯※雪 2024-10-07 09:05:53

尝试在 onDestroy 的第一行设置 BP 并验证 vars/members 以查找哪个为 null

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文