-2

私は自分のプロジェクトで PayPal 機能を次のように設計しました。

public class MypaypalActivity extends Activity implements OnClickListener{

    /** Called when the activity is first created. */
    @Override

public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        LinearLayout mLinLay= new LinearLayout(this);

        setContentView(R.layout.main);

        PayPal pp = PayPal.initWithAppID(this, "APP-

80W284485P519543T",PayPal.ENV_SANDBOX);


        LinearLayout layoutSimplePayment = new LinearLayout(this);

        layoutSimplePayment.setLayoutParams(new LayoutParams(

                LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

        layoutSimplePayment.setOrientation(LinearLayout.VERTICAL);

        CheckoutButton launchSimplePayment = pp.getCheckoutButton(this,

                PayPal.BUTTON_118x24, CheckoutButton.TEXT_PAY);

        launchSimplePayment.setOnClickListener( this);

        layoutSimplePayment.addView(launchSimplePayment);

        mLinLay.addView(layoutSimplePayment);

        setContentView(mLinLay);

    }

これは一度だけ非常に正しく機能します。PayPal ボタンをもう一度押すと、このアプリケーションがクラッシュします。catlog に PayPal を 2 回初期化したというエラーがあるため、getInstance(); を使用します。初期化後。

これにはどうすればよいですか?

4

1 に答える 1

2

ちょっとこれは私の質問に対する解決策です。私は自分でこれを行いました。

PayPal pp = PayPal.getInstance();
        if (pp == null) {
            try {
                pp = PayPal.initWithAppID(this, "", PayPal.ENV_NONE);
            } catch (IllegalStateException e) {
                throw new RuntimeException(e);
            }
            pp.setShippingEnabled(false);
        }

皆さん、ありがとうございました...

于 2011-10-13T07:01:59.217 に答える