Android in-app billing purchase activity is crashing the app.
i have a in app billing activity that buys subscription for removing ads for 1 month.
But when i am clicking remove ads button that calls billing activity, the app is crashing.
Here is my logcat output:
12-18 02:07:51.872: E/chromium(694): [ERROR:browser_gpu_channel_host_factory.cc(258)] Failed to init browser shader disk cache.
12-18 02:07:51.883: E/libEGL(694): validate_display:255 error 3008 (EGL_BAD_DISPLAY)
12-18 02:07:51.888: W/cr.media(694): Requires BLUETOOTH permission
12-18 02:07:51.907: W/art(694): Attempt to remove non-JNI local reference, dumping thread
12-18 02:07:51.914: W/AwContents(694): onDetachedFromWindow called when already detached. Ignoring
12-18 02:07:52.278: W/VideoCapabilities(694): Unrecognized profile 2130706433 for video/avc
12-18 02:07:52.310: I/VideoCapabilities(694): Unsupported profile 4 for video/mp4v-es
12-18 02:07:52.316: I/OMXClient(694): Using client-side OMX mux.
12-18 02:07:52.396: I/Ads(694): Starting ad request.
12-18 02:07:52.401: I/Ads(694): Please set theme of AdActivity to @android:style/Theme.Translucent to enable transparent background interstitial ad.
12-18 02:07:52.408: I/Ads(694): Starting ad request.
12-18 02:07:52.411: I/Ads(694): Please set theme of AdActivity to @android:style/Theme.Translucent to enable transparent background interstitial ad.
12-18 02:07:52.420: D/OpenGLRenderer(694): Use EGL_SWAP_BEHAVIOR_PRESERVED: true
12-18 02:07:52.439: D/billing(694): In app billing is set up
12-18 02:07:52.542: I/OpenGLRenderer(694): Initialized EGL, version 1.4
12-18 02:07:54.634: D/AndroidRuntime(694): Shutting down VM
12-18 02:07:54.636: E/AndroidRuntime(694): FATAL EXCEPTION: main
12-18 02:07:54.636: E/AndroidRuntime(694): Process: com.ifreedomapp.v3, PID: 694
12-18 02:07:54.636: E/AndroidRuntime(694): java.lang.NullPointerException: Attempt to invoke virtual method 'void android.app.Activity.startIntentSenderForResult(android.content.IntentSender, int, android.content.Intent, int, int, int)' on a null object reference
12-18 02:07:54.636: E/AndroidRuntime(694): at com.ifreedom.util.IabHelper.launchPurchaseFlow(IabHelper.java:431)
12-18 02:07:54.636: E/AndroidRuntime(694): at com.ifreedom.util.IabHelper.launchPurchaseFlow(IabHelper.java:347)
12-18 02:07:54.636: E/AndroidRuntime(694): at com.ifreedom.StatusActivity$4.onClick(StatusActivity.java:379)
12-18 02:07:54.636: E/AndroidRuntime(694): at android.view.View.performClick(View.java:5204)
12-18 02:07:54.636: E/AndroidRuntime(694): at android.view.View$PerformClick.run(View.java:21153)
12-18 02:07:54.636: E/AndroidRuntime(694): at android.os.Handler.handleCallback(Handler.java:739)
12-18 02:07:54.636: E/AndroidRuntime(694): at android.os.Handler.dispatchMessage(Handler.java:95)
12-18 02:07:54.636: E/AndroidRuntime(694): at android.os.Looper.loop(Looper.java:148)
12-18 02:07:54.636: E/AndroidRuntime(694): at android.app.ActivityThread.main(ActivityThread.java:5417)
12-18 02:07:54.636: E/AndroidRuntime(694): at java.lang.reflect.Method.invoke(Native Method)
12-18 02:07:54.636: E/AndroidRuntime(694): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
12-18 02:07:54.636: E/AndroidRuntime(694): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
12-18 02:07:57.191: I/GAV3(694): Thread[GAThread,5,main]: No campaign data found.
Here is my subscribe button activity:
bsubscribe.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (billing_error == "") {
if (!isSubscribed)
mHelper.launchPurchaseFlow(getParent(), SKU_SUBSCRIPTION, 9999, mPurchaseFinishedListener,"");
else
Toast.makeText(mContext, getResources().getString(R.string.already_subs), Toast.LENGTH_SHORT).show();
} else
Toast.makeText(mContext, "There's some error in billing : " + billing_error, Toast.LENGTH_LONG).show();
}
});
}
And this is the setbilling function :
private void setInAppBilling() {
mHelper = new IabHelper(mContext, bill_key);
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
public void onIabSetupFinished(IabResult result) {
if (mHelper == null)
return;
if (!result.isSuccess()) {
Log.d("billing", "probelem in setting billing" + result);
billing_error = "" + result;
}
if (result.isSuccess()) {
Log.d("billing", "In app billing is set up");
mHelper.queryInventoryAsync(new IabHelper.QueryInventoryFinishedListener() {
@Override
public void onQueryInventoryFinished(IabResult result, Inventory inv) {
if (inv.getPurchase(SKU_SUBSCRIPTION) == null) {
edit.putBoolean("subscription", false);
edit.commit();
} else {
edit.putBoolean("subscription", true);
edit.commit();
bsubscribe.setVisibility(View.GONE);
}
}
});
}
}
});
}
IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener() {
public void onIabPurchaseFinished(IabResult result, Purchase info) {
if (result.isFailure()) {
Toast.makeText(mContext, getResources().getString(R.string.error_subs), Toast.LENGTH_SHORT).show();
return;
}
if (info.getSku().equals(SKU_SUBSCRIPTION)) {
Toast.makeText(mContext, getResources().getString(R.string.success_subs), Toast.LENGTH_SHORT).show();
edit.putBoolean("subscription", true);
edit.commit();
}
}
};
Set billing is called from OnCreate of the activity.
The app is crashing when i click remove ads button (bsubscribe)