1

下面显示了我用于在我的 android 应用程序中初始化 paypal 对象的代码。运行时错误是由 doInBackground() 引起的,所以我认为这可能是由于 payPal.isLibraryInitialized() 返回的错误。

你们有在 android 应用程序中集成 paypal 的经验吗?

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();
      }
    }
  };
4

2 回答 2

2

如果您添加了jar文件但未正确包含,则会出现此类错误。右键单击您的项目,然后转到属性--java构建路径--order和export。检查jar旁边是否有复选框。应该是检查。再次运行您的应用程序并检查是否存在相同的问题。

于 2012-07-27T10:04:04.933 回答
1

也许你忘了把这个权限放在 AndroidManifest.xml

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>   
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
于 2012-08-06T14:29:58.217 回答