本文介绍了Android的InApp购买空指针异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我实施了inApp购买我的应用程序,但有时它给了我NPE,下面是堆栈跟踪。我可以张贴code也可以,如果有兴趣的人。
了java.lang.RuntimeException:无法启动服务com.market.BillingService@48400380与空:显示java.lang.NullPointerException
在android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3063)
在android.app.ActivityThread.access $ 3600(ActivityThread.java:125)
在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:2096)
在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:871)
在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629)
在dalvik.system.NativeStart.main(本机方法)
显示java.lang.NullPointerException:产生的原因
在com.market.BillingService.handleCommand(BillingService.java:369)
在com.market.BillingService.onStart(BillingService.java:359)
在android.app.Service.onStartCommand(Service.java:420)
在android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3053)
... 10更多
显示java.lang.NullPointerException
在com.market.BillingService.handleCommand(BillingService.java:369)
在com.market.BillingService.onStart(BillingService.java:359)
在android.app.Service.onStartCommand(Service.java:420)
在android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3053)
在android.app.ActivityThread.access $ 3600(ActivityThread.java:125)
在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:2096)
在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:871)
在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629)
在dalvik.system.NativeStart.main(本机方法)
下面去相关code
@覆盖
保护无效的OnStart(){
super.onStart();
ResponseHandler.register(mDungeonsPurchaseObserver);
}
@覆盖
保护无效的onStop(){
super.onStop();
ResponseHandler.unregister(mDungeonsPurchaseObserver);
}
@覆盖
保护无效的onDestroy(){
super.onDestroy();
mBillingService.unbind();
}
而在OnCreate中()
mDungeonsPurchaseObserver =新WMBPurchaseObserver(mHandler);
mBillingService =新BillingService有();
mBillingService.setContext(BuyModel.this);
ResponseHandler.register(mDungeonsPurchaseObserver);
求购巴顿的onClick
如果(!mBillingService.checkBillingSupported())
{
的ShowDialog(DIALOG_CANNOT_CONNECT_ID);
}
mBillingService.requestPurchase(android.test.purchased,NULL);
解决方案
在你BillingService.java OnStart方法后卫空意图像这样
如果(NULL!=意图){
handleCommand(意向,startId);
}
我相信这是由空意图。试试!
I had implemented inApp purchase in my application but sometimes it gives me NPE, below is stack trace. I can post the code also if anyone interested.
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)
Here goes relevant code
@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();
}
And in OnCreate()
mDungeonsPurchaseObserver = new WMBPurchaseObserver(mHandler);
mBillingService = new BillingService();
mBillingService.setContext(BuyModel.this);
ResponseHandler.register(mDungeonsPurchaseObserver);
onClick of buy Button
if (!mBillingService.checkBillingSupported())
{
showDialog(DIALOG_CANNOT_CONNECT_ID);
}
mBillingService.requestPurchase("android.test.purchased", null);
解决方案
In your BillingService.java onStart method guard for null intent like this
if (null != intent) {
handleCommand(intent, startId);
}
I believe this is caused by null intent. Try out!
这篇关于Android的InApp购买空指针异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!