android - Google Billing V3 null pointer exception -
basically want static test of google billing v3,before doing real online test using beta version thing. when try run program,i following part of exception...
caused by: java.lang.illegalargumentexception: connection null @ android.app.contextimpl.bindservicecommon (contextimpl.java:1935) @ android.app.contextimpl.bindservice(contextimpl.java:1921) @ android.content.contextwrapper.bindservice (contextwrapper.java:529) @ victory.walkto.paymenttestb.mainactivity. oncreate(mainactivity.java:37) @ android.app.activity.performcreate(activity.java:5451)
the program wrote following.
public class mainactivity extends activity { iinappbillingservice mservice; serviceconnection connection; string inappid = "android.test.purchased"; //replace in-app product id @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); intent serviceintent = new intent("com.android.vending.billing.inappbillingservice.bind"); serviceintent.setpackage("com.android.vending"); bindservice(serviceintent,connection, context.bind_auto_create); connection = new serviceconnection() { @override public void onservicedisconnected(componentname name) { mservice = null; } @override public void onserviceconnected(componentname name, ibinder service) { mservice = iinappbillingservice.stub.asinterface(service); } }; button purchasebtn = (button) findviewbyid(r.id.purchase); purchasebtn.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { arraylist skulist = new arraylist(); skulist.add(inappid); bundle queryskus = new bundle(); queryskus.putstringarraylist("item_id_list", skulist); bundle skudetails; try { skudetails = mservice.getskudetails(3, getpackagename(), "inapp", queryskus); int response = skudetails.getint("response_code"); if (response == 0) { arraylist<string> responselist = skudetails .getstringarraylist("details_list"); (string thisresponse : responselist) { jsonobject object = new jsonobject(thisresponse); string sku = object.getstring("productid"); string price = object.getstring("price"); if (sku.equals(inappid)) { system.out.println("price " + price); bundle buyintentbundle = mservice .getbuyintent(3, getpackagename(), sku, "inapp", "bgoa+v7g/yqdxvkrqq+jtfn4uqzbpiqjo4pf9rzj"); pendingintent pendingintent = buyintentbundle .getparcelable("buy_intent"); startintentsenderforresult( pendingintent.getintentsender(), 1001, new intent(), integer.valueof(0), integer.valueof(0), integer.valueof(0)); } } } } catch (remoteexception e) { // todo auto-generated catch block e.printstacktrace(); } catch (jsonexception e) { // todo auto-generated catch block e.printstacktrace(); } catch (intentsender.sendintentexception e) { // todo auto-generated catch block e.printstacktrace(); } } }); } @override protected void onactivityresult(int requestcode, int resultcode, intent data) { if (requestcode == 1001) { string purchasedata = data.getstringextra("inapp_purchase_data"); if (resultcode == result_ok) { try { jsonobject jo = new jsonobject(purchasedata); string sku = jo.getstring(inappid); toast.maketext( mainactivity.this, "you have bought " + sku + ". excellent choice,adventurer!", toast.length_long).show(); } catch (jsonexception e) { system.out.println("failed parse purchase data."); e.printstacktrace(); } } } } @override public void ondestroy() { super.ondestroy(); if (connection != null) { unbindservice(connection); } } }
i found out google wallet can not downloaded in phone if using greek account!!! paypal stopped operation greece due banking problems!!!
you need first create service connection , bind service.
// first connection = new serviceconnection() { @override public void onservicedisconnected(componentname name) { mservice = null; } @override public void onserviceconnected(componentname name, ibinder service) { mservice = iinappbillingservice.stub.asinterface(service); } }; // bindservice(serviceintent,connection, context.bind_auto_create);
Comments
Post a Comment