java - How do I solve IabHelper Error -
i have error on 264 , 163 of 2 file in editor it's fine
line 264 :
if (!mcontext.getpackagemanager().queryintentservices(serviceintent, 0).isempty()) {
line 163 :
mhelper.startsetup(new iabhelper.oniabsetupfinishedlistener() {
i can't find why activity unable start logcat:
1266-1266/com.exercise.androidhtml e/androidruntime﹕ fatal exception: main java.lang.runtimeexception: unable start activity componentinfo{com.exercise.androidhtml/com.company.clipboard.androidhtmlactivity}: java.lang.nullpointerexception @ android.app.activitythread.performlaunchactivity(activitythread.java:2059) @ android.app.activitythread.handlelaunchactivity(activitythread.java:2084) @ android.app.activitythread.access$600(activitythread.java:130) @ android.app.activitythread$h.handlemessage(activitythread.java:1195) @ android.os.handler.dispatchmessage(handler.java:99) @ android.os.looper.loop(looper.java:137) @ android.app.activitythread.main(activitythread.java:4745) @ java.lang.reflect.method.invokenative(native method) @ java.lang.reflect.method.invoke(method.java:511) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:786) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:553) @ dalvik.system.nativestart.main(native method) caused by: java.lang.nullpointerexception @ com.company.clipboard.util.iabhelper.startsetup(iabhelper.java:264) @ com.company.clipboard.androidhtmlactivity.oncreate(androidhtmlactivity.java:163) @ android.app.activity.performcreate(activity.java:5008) @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1079) @ android.app.activitythread.performlaunchactivity(activitythread.java:2023) @ android.app.activitythread.handlelaunchactivity(activitythread.java:2084) @ android.app.activitythread.access$600(activitythread.java:130) @ android.app.activitythread$h.handlemessage(activitythread.java:1195) @ android.os.handler.dispatchmessage(handler.java:99) @ android.os.looper.loop(looper.java:137) @ android.app.activitythread.main(activitythread.java:4745) @ java.lang.reflect.method.invokenative(native method) @ java.lang.reflect.method.invoke(method.java:511) @ android.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:786) @ android.android.internal.os.zygoteinit.main(zygoteinit.java:553) @ dalvik.system.nativestart.main(native method)
this whole block of payment contain line 163:
//===================================================== string base64encodedpublickey = "mihnma0gcsqgsib3dqebaquaa4g7adcbtwkbrwdtuwvdlt6clzldcqgzxcyyweebp8vf/6qm7qckuqpdxg6hb71hvu8lmceo0vcys2xpzxt03iw7lhkxrtdsxi5h9whlesfy9squc0ugpd+n5ne+i6zcib/rb2wscvzfa3jciyrbmsvez+dwaqshfq6cnuawl0fbz4nfjntzhkyhanm6ptjquo9jsj+pa9pv38c3o5y3alcvpmcaweaaq=="; mhelper = new iabhelper(this, base64encodedpublickey); mgotinventorylistener = new iabhelper.queryinventoryfinishedlistener() { public void onqueryinventoryfinished(iabresult result, inventory inventory) { log.d(tag, "query inventory finished."); if (result.isfailure()) { log.d(tag, "failed query inventory: " + result); return; } else { log.d(tag, "query inventory successful."); // user have premium upgrade? mispremium = inventory.haspurchase(sku_premium); if (mispremium){ masrafseke(inventory.getpurchase(sku_premium)); } // update ui accordingly log.d(tag, "user " + (mispremium ? "premium" : "not premium")); } log.d(tag, "initial inventory query finished; enabling main ui."); } }; mpurchasefinishedlistener = new iabhelper.oniabpurchasefinishedlistener() { public void oniabpurchasefinished(iabresult result, purchase purchase) { if (result.isfailure()) { log.d(tag, "error purchasing: " + result); return; } else if (purchase.getsku().equals(sku_premium)) { // give user access premium content , update ui toast.maketext(androidhtmlactivity.this,"خرید موفق",toast.length_short).show(); masrafseke(purchase); } } }; log.d(tag, "starting setup."); mhelper.startsetup(new iabhelper.oniabsetupfinishedlistener() { public void oniabsetupfinished(iabresult result) { log.d(tag, "setup finished."); if (!result.issuccess()) { // oh noes, there problem. log.d(tag, "problem setting in-app billing: " + result); } // hooray, iab set up! mhelper.queryinventoryasync(mgotinventorylistener); } });
seems issue of iabhelper. method queryintentservices
returns null
, instead empty list.
try update code this:
intent serviceintent = new intent("com.android.vending.billing.inappbillingservice.bind"); if (!mcontext.getpackagemanager().queryintentservices(serviceintent, 0).isempty()) { // service available handle intent mcontext.bindservice(serviceintent, mserviceconn, context.bind_auto_create); } else { // no service available handle intent if (listener != null) { listener.oniabsetupfinished( new iabresult(billing_response_result_billing_unavailable, "billing service unavailable on device.")); } }
to this:
intent serviceintent = new intent("com.android.vending.billing.inappbillingservice.bind"); list<resolveinfo> intentservices = mcontext.getpackagemanager().queryintentservices(serviceintent, 0); if (intentservices != null && intentservices.isempty() == false) { // service available handle intent mcontext.bindservice(serviceintent, mserviceconn, context.bind_auto_create); } else { // no service available handle intent if (listener != null) { listener.oniabsetupfinished( new iabresult(billing_response_result_billing_unavailable, "billing service unavailable on device.")); } }
Comments
Post a Comment