The following shows my code used to initialize a paypal object in my android app.
Runtime error is resulted from doInBackground() so i think it is probably due to false returned by payPal.isLibraryInitialized().
Do you guys have experience on paypal integration in android app?
private class PayPalInitializer extends AsyncTask<Void, Void, Boolean> {
private static final String APP_ID = "APP-80W284485P519543T";
private Context mContext;
private ProgressDialog mProgressDialog;
public PayPalInitializer(Context context) {
mContext = context;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
mProgressDialog = new ProgressDialog(mContext);
mProgressDialog.setMessage("...");
mProgressDialog.show();
}
@Override
protected Boolean doInBackground(Void... params) {
boolean success = false;
PayPal payPal = PayPal.getInstance();
if (payPal == null) {
payPal = PayPal.initWithAppID(mContext, APP_ID, PayPal.ENV_SANDBOX);
payPal.setFeesPayer(PayPal.FEEPAYER_EACHRECEIVER);
// Set to true if the transaction will require shipping.
payPal.setShippingEnabled(true);
if (payPal.isLibraryInitialized()) {
success = true;
}
}
return success;
}
@Override
protected void onPostExecute(Boolean result) {
super.onPostExecute(result);
mProgressDialog.hide();
mProgressDialog = null;
if (result) {
setupButton();
} else {
Toast.makeText(getApplicationContext(), "", Toast.LENGTH_SHORT).show();
}
}
};
This type of error occurs if you have added jar file but it is not included properly.Right click on your project and then go to properties–java build path–order and export.There check if checkbox beside the jar.It should be checked.run your app again and check if same issue exists.