我正在尝试在我的应用程序中使用InAppBilling。我之前使用过类似的代码并且它有效但现在我遇到了错误!我的logcat:
08-19 16:19:38.096: E/AndroidRuntime(27034): FATAL EXCEPTION: Thread-3594
08-19 16:19:38.096: E/AndroidRuntime(27034): java.lang.NullPointerException
08-19 16:19:38.096: E/AndroidRuntime(27034): at com.taygon.tick_one.Buy$2.run(Buy.java:101)
08-19 16:19:38.096: E/AndroidRuntime(27034): at java.lang.Thread.run(Thread.java:841)
当我双击第3行时,它突出显示getBuyIntent(...)
功能。这是我的代码:
IInAppBillingService mService;
ServiceConnection mServiceConn = new ServiceConnection() {
@Override
public void onServiceDisconnected(ComponentName name) {
mService = null;
}
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
mService = IInAppBillingService.Stub.asInterface(service);
}
};
@Override
public void onDestroy() {
super.onDestroy();
if (mServiceConn != null) {
try {
unbindService(mServiceConn);
} catch (Exception ex) {
}
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 1372) {
String purchaseData = data.getStringExtra("INAPP_PURCHASE_DATA");
if (resultCode == RESULT_OK) {
try {
JSONObject jo = new JSONObject(purchaseData);
Toast.makeText(Buy.this, "Thank you",
Toast.LENGTH_SHORT).show();
} catch (JSONException e) {
Toast.makeText(Buy.this,
"Error Happend!",
Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
}
else
Toast.makeText(Buy.this, "Not Compeleted",
Toast.LENGTH_SHORT).show();
}
}
public void buy_package() {
try {
Bundle buyIntentBundle;
buyIntentBundle = mService
.getBuyIntent(
3,
getApplicationContext().getPackageName(),
"Product Serial Number",
"inapp",
"My App RSA Code");
PendingIntent pendingIntent = buyIntentBundle
.getParcelable("BUY_INTENT");
startIntentSenderForResult(pendingIntent.getIntentSender(),
1372, new Intent(), Integer.valueOf(0),
Integer.valueOf(0), Integer.valueOf(0));
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SendIntentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}