android - NullPointerException on getPurchases() -
i trying purchases of user , , claim billing service null , process running in asynctask ,btw newbie inapp billing service , here parts of code :
my service connection :
iinappbillingservice billingservice; private serviceconnection serviceconnection = new serviceconnection() { @override public void onservicedisconnected(componentname name) { billingservice = null ; } @override public void onserviceconnected(componentname name, ibinder service) { billingservice = iinappbillingservice.stub.asinterface(service); } };
part of asynctask :
@override protected string doinbackground(activity... params) { final activity mactivity = params[0]; bindservice(new intent("com.android.vending.billing.inappbillingservice.bind"), serviceconnection, context.bind_auto_create); connectivitymanager c = (connectivitymanager) getsystemservice(service.connectivity_service); networkinfo ni = c.getactivenetworkinfo(); if(ni == null || ! ni.isconnected()){ // stuff }else{ bundle purchases = null; try { purchases = billingservice. getpurchases(3, "le.wild.packagename", "inapp", null); } catch (remoteexception e) { // todo auto-generated catch block e.printstacktrace(); } if(purchases.getint("response_code") == 0){ arraylist<string> items = purchases.getstringarraylist("inapp_purchase_item_list"); arraylist<string> itemsdata = purchases.getstringarraylist("inapp_purchase_data_list"); boolean o = false; for(int = 0 ; itemsdata.size() > ; i++){ if(items.get(i).contains("le.wild.itemname")){ o = false; continue; }else{ o = true; } } // stuff }
i can using same way consuming purchases , getting buy intents , other functions , here , not working ! if need anymore info or here , in advance !
edit :
stacktrace :
07-22 15:58:12.830: e/androidruntime(12719): fatal exception: asynctask #1 07-22 15:58:12.830: e/androidruntime(12719): java.lang.runtimeexception: error occured while executing doinbackground() 07-22 15:58:12.830: e/androidruntime(12719): @ android.os.asynctask$3.done(asynctask.java:299) 07-22 15:58:12.830: e/androidruntime(12719): @ java.util.concurrent.futuretask.finishcompletion(futuretask.java:352) 07-22 15:58:12.830: e/androidruntime(12719): @ java.util.concurrent.futuretask.setexception(futuretask.java:219) 07-22 15:58:12.830: e/androidruntime(12719): @ java.util.concurrent.futuretask.run(futuretask.java:239) 07-22 15:58:12.830: e/androidruntime(12719): @ android.os.asynctask$serialexecutor$1.run(asynctask.java:230) 07-22 15:58:12.830: e/androidruntime(12719): @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1080) 07-22 15:58:12.830: e/androidruntime(12719): @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:573) 07-22 15:58:12.830: e/androidruntime(12719): @ java.lang.thread.run(thread.java:856) 07-22 15:58:12.830: e/androidruntime(12719): caused by: java.lang.nullpointerexception 07-22 15:58:12.830: e/androidruntime(12719): @ seaskyways.quadcoremanagerplus.coresmanagement$2.doinbackground(coresmanagement.java:372) 07-22 15:58:12.830: e/androidruntime(12719): @ seaskyways.quadcoremanagerplus.coresmanagement$2.doinbackground(coresmanagement.java:1) 07-22 15:58:12.830: e/androidruntime(12719): @ android.os.asynctask$2.call(asynctask.java:287) 07-22 15:58:12.830: e/androidruntime(12719): @ java.util.concurrent.futuretask.run(futuretask.java:234) 07-22 15:58:12.830: e/androidruntime(12719): ... 4 more
bindservice async. take little bit of time before onserviceconnected called set interface. should bind service much earlier before need call it.
also naming variable starting uppercase confusing.
Comments
Post a Comment