【问题标题】:Android: What make my application crash?Android:是什么让我的应用程序崩溃?
【发布时间】:2012-01-16 07:49:33
【问题描述】:

我每天都会收到一些错误,我不确定发生了什么。

如果需要更多信息,请告诉我。

我可能没有为任何事情提供足够的信息。

这是我在开发者控制台中遇到的错误:

java.lang.RuntimeException: Unable to destroy activity {com.Calculator.SalesTaxCalculator/com.Calculator.SalesTaxCalculator.Calculator}: java.lang.NullPointerException
at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3199)
at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3264)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3380)
at android.app.ActivityThread.access$1600(ActivityThread.java:145)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1049)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:150)
at android.app.ActivityThread.main(ActivityThread.java:4369)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:846)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:604)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at android.content.ComponentName.<init>(ComponentName.java:75)
at android.content.Intent.<init>(Intent.java:2920)
at com.Calculator.SalesTaxCalculator.BillingHelper.stopService(BillingHelper.java:265)
at com.Calculator.SalesTaxCalculator.Calculator.onDestroy(Calculator.java:302)
at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3181)
... 12 more

第 302 行

protected void onDestroy() {

从第 301 行及以后(这是该页面上的最后一组代码。)

@Override
protected void onDestroy() {
    BillingHelper.stopService();
    super.onDestroy();

}
}

BillingHelper 中的 StopService 方法

public static void stopService(){
                mContext.stopService(new Intent(mContext, BillingService.class));
                mService = null;
                mContext = null;
                mCompletedHandler = null;
                Log.i(TAG, "Stopping Service");
        }
}

有人放入了一个应用程序甚至无法打开的崩溃报告 cmets。更多信息是它使用共享首选项将数字保存在计算器中。还有一个使用应用内计费服务的捐赠按钮。

【问题讨论】:

  • Calculator.java:302 也发布此行。
  • 我认为您应该粘贴的最低限度是破坏您所有活动的代码。和计算器代码。因为看起来有和错误。
  • BillingHelper.stopService() 也可能包含错误
  • 请提供SalesTaxCalculator.java和Calculator.java文件的示例代码。
  • 添加了更多信息,请查看。

标签: java android crash report nullpointerexception


【解决方案1】:

改成调用 super.onDestroy();首先是其他东西,例如:

@Override
protected void onDestroy() {
    super.onDestroy();
    BillingHelper.stopService();
}

【讨论】:

  • 你知道有什么方法可以测试这是否能解决问题吗?我不知道那次崩溃是关于什么的,也不知道如何重新制作它,在 15,000 多人中,我只有 16 人遇到了这个问题。
  • 我测试过我的应用程序的每台设备都可以与该应用程序配合使用。当我在我的应用中添加 Billing 时,这个问题就开始了。
  • BillingHelper 的 StopService 方法是什么?
  • 它与您用于启动服务的上下文相同吗?您是否使用应用程序级别上下文或活动级别上下文来启动服务?无论哪种情况,您都应该使用相同的上下文来启动/停止您的服务。如果它的应用程序的上下文,不要将你的上下文设置为 null
  • 它与您用于启动服务的上下文相同吗?您是否使用应用程序级别上下文或活动级别上下文来启动服务?无论哪种情况,您都应该使用相同的上下文来启动/停止您的服务。如果它的应用程序的上下文,不要将你的上下文设置为 null
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多