我在结账后收到了一个ArrayIndexOutOfBoundsException
并导致交易被取消。我正在使用 SANDBOX 测试帐户。
我在这里提供来自堆栈跟踪的 block :
FATAL EXCEPTION: Thread-481
E/AndroidRuntime(15495): java.lang.ArrayIndexOutOfBoundsException: length=4; index=6
at com.paypal.android.MEP.PayPal.getPayType(Unknown Source)
at com.paypal.android.a.m.f(Unknown Source)
at com.paypal.android.a.b.y(Unknown Source)
at com.paypal.android.a.b.f(Unknown Source)
at com.paypal.android.a.k.run(Unknown Source)
我的付款任务类是 -
public class PaymentTask extends AsyncTask<Void, Void, Void>{
private Handler mHandler;
private Activity mActivity;
// The PayPal server to be used - can also be ENV_NONE and ENV_LIVE
private static final int server = PayPal.ENV_SANDBOX;
// The ID of your application that you received from PayPal
private static final String appID = "APP-80W284485P519543T";
public PaymentTask(Activity mActivity, Handler mHandler){
super();
this.mHandler = mHandler;
this.mActivity = mActivity;
}
@Override
protected Void doInBackground(Void... params) {
PayPal pp = PayPal.getInstance();
// If the library is already initialized, then we don't need to initialize it again.
if(pp == null) {
pp = PayPal.initWithAppID(mActivity, appID, server);
pp.setLanguage("en_US"); // Sets the language for the library.
pp.setFeesPayer(PayPal.FEEPAYER_EACHRECEIVER);
// Set to true if the transaction will require shipping.
pp.setShippingEnabled(true);
pp.setDynamicAmountCalculationEnabled(false);
}
return null;
}
@Override
protected void onPostExecute(Void result) {
mHandler.sendEmptyMessage(0);
super.onPostExecute(result);
}
点击结帐按钮时执行的代码 -
PayPalPayment newPayment = new PayPalPayment();
newPayment.setSubtotal(new BigDecimal(Integer.parseInt("10"));
newPayment.setCurrencyType("USD");
newPayment.setRecipient("my.mail@gmail.com");
newPayment.setPaymentType(PayPal.PAYMENT_SUBTYPE_DONATIONS);
newPayment.setMerchantName("Support the initiative");
// Sets the memo. This memo will be part of the notification sent by PayPal to the necessary parties.
newPayment.setMemo("Thanks for contributing generously!");
Intent paypalIntent = PayPal.getInstance().checkout(newPayment, getSherlockActivity());
startActivityForResult(paypalIntent, request);
}
mCheckoutButton.updateButton();
最佳答案
您正在使用 PayPal.PAYMENT_SUBTYPE_DONATIONS
,这是一种支付子类型,作为支付类型。您应该使用其中一种来定义付款类型:PayPal.PAYMENT_TYPE_GOODS
、PayPal.PAYMENT_TYPE_SERVICE
、PayPal.PAYMENT_TYPE_PERSONAL
或 PayPal。 PAYMENT_TYPE_NONE
。
如果你想设置子类型,像这样设置:
newPayment.setPaymentSubtype(PayPal.PAYMENT_SUBTYPE_DONATIONS);
关于android - Paypal 库中的 ArrayIndexOutOfBoundsException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14059722/