gpt4 book ai didi

Android InApp Purchase空指针异常

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:12:13 26 4
gpt4 key购买 nike

我已经在我的应用程序中实现了应用内购买,但有时它会给我 NPE,下面是堆栈跟踪。如果有人感兴趣,我也可以发布代码。

java.lang.RuntimeException: Unable to start service com.market.BillingService@48400380 with null: java.lang.NullPointerException
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3063)
at android.app.ActivityThread.access$3600(ActivityThread.java:125)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2096)
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:871)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.market.BillingService.handleCommand(BillingService.java:369)
at com.market.BillingService.onStart(BillingService.java:359)
at android.app.Service.onStartCommand(Service.java:420)
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3053)
... 10 more
java.lang.NullPointerException
at com.market.BillingService.handleCommand(BillingService.java:369)
at com.market.BillingService.onStart(BillingService.java:359)
at android.app.Service.onStartCommand(Service.java:420)
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3053)
at android.app.ActivityThread.access$3600(ActivityThread.java:125)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2096)
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:871)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629)
at dalvik.system.NativeStart.main(Native Method)

这里是相关代码

@Override
protected void onStart() {
super.onStart();
ResponseHandler.register(mDungeonsPurchaseObserver);
}
@Override
protected void onStop() {
super.onStop();
ResponseHandler.unregister(mDungeonsPurchaseObserver);
}

@Override
protected void onDestroy() {
super.onDestroy();
mBillingService.unbind();
}

并在 OnCreate() 中

mDungeonsPurchaseObserver = new WMBPurchaseObserver(mHandler);

mBillingService = new BillingService();
mBillingService.setContext(BuyModel.this);
ResponseHandler.register(mDungeonsPurchaseObserver);

点击购买按钮

if (!mBillingService.checkBillingSupported())
{
showDialog(DIALOG_CANNOT_CONNECT_ID);
}
mBillingService.requestPurchase("android.test.purchased", null);

最佳答案

在你的 BillingService.java onStart 方法中为这样的空 Intent 守卫

 if (null != intent) {
handleCommand(intent, startId);
}

我认为这是由无效 Intent 引起的。试试吧!

关于Android InApp Purchase空指针异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6759802/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com