Paypal活动崩溃

时间:2013-09-10 09:20:41

标签: android button android-activity paypal android-linearlayout

我正在尝试打开包含Paypal按钮的Activity,但由于某种原因它会崩溃。

这是我显示Paypal按钮并打开Paypal活动的代码(此处未显示OnActivityResult,现在它并不重要。):

PayPal ppObj = PayPal.initWithAppID(this.getBaseContext(), "APP-80W284485P519543T", PayPal.ENV_SANDBOX);

Inside OnCreate:

LinearLayout mLinLay= new LinearLayout(this);
        setContentView(R.layout.activity_add);
LinearLayout layoutSimplePayment = new LinearLayout(this);
        layoutSimplePayment.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
        layoutSimplePayment.setOrientation(LinearLayout.VERTICAL);
        CheckoutButton launchSimplePayment = ppObj.getCheckoutButton(this, PayPal.BUTTON_278x43, CheckoutButton.TEXT_PAY);

        launchSimplePayment.setOnClickListener(this);   
        layoutSimplePayment.addView(launchSimplePayment);
        mLinLay.addView(layoutSimplePayment);

        setContentView(mLinLay);

的OnClick:

public void onClick(View v) {
        PayPalPayment payment = new PayPalPayment();
        payment.setSubtotal(new BigDecimal("10.00"));
        payment.setCurrencyType("USD");
        payment.setRecipient("mymail@gmail.com");
        payment.setPaymentType(PayPal.PAYMENT_TYPE_GOODS);
        payment.setMerchantName("Company");
        Intent checkoutIntent = PayPal.getInstance().checkout(payment, this);
        startActivityForResult(checkoutIntent, 1);
    }

logcat的:

09-10 12:14:07.746: W/dalvikvm(27898): threadid=1: thread exiting with uncaught exception (group=0x41f0a930)
09-10 12:14:07.750: E/AndroidRuntime(27898): FATAL EXCEPTION: main
09-10 12:14:07.750: E/AndroidRuntime(27898): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.free/com.example.free.Add}: java.lang.NullPointerException
09-10 12:14:07.750: E/AndroidRuntime(27898):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2308)
09-10 12:14:07.750: E/AndroidRuntime(27898):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2358)
09-10 12:14:07.750: E/AndroidRuntime(27898):    at android.app.ActivityThread.access$600(ActivityThread.java:153)
09-10 12:14:07.750: E/AndroidRuntime(27898):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1247)
09-10 12:14:07.750: E/AndroidRuntime(27898):    at android.os.Handler.dispatchMessage(Handler.java:99)
09-10 12:14:07.750: E/AndroidRuntime(27898):    at android.os.Looper.loop(Looper.java:137)
09-10 12:14:07.750: E/AndroidRuntime(27898):    at android.app.ActivityThread.main(ActivityThread.java:5227)
09-10 12:14:07.750: E/AndroidRuntime(27898):    at java.lang.reflect.Method.invokeNative(Native Method)
09-10 12:14:07.750: E/AndroidRuntime(27898):    at java.lang.reflect.Method.invoke(Method.java:511)
09-10 12:14:07.750: E/AndroidRuntime(27898):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
09-10 12:14:07.750: E/AndroidRuntime(27898):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
09-10 12:14:07.750: E/AndroidRuntime(27898):    at dalvik.system.NativeStart.main(Native Method)
09-10 12:14:07.750: E/AndroidRuntime(27898): Caused by: java.lang.NullPointerException
09-10 12:14:07.750: E/AndroidRuntime(27898):    at com.paypal.android.MEP.PayPal.getDensity(Unknown Source)
09-10 12:14:07.750: E/AndroidRuntime(27898):    at com.paypal.android.MEP.CheckoutButton.a(Unknown Source)
09-10 12:14:07.750: E/AndroidRuntime(27898):    at com.paypal.android.MEP.PayPal.getCheckoutButton(Unknown Source)
09-10 12:14:07.750: E/AndroidRuntime(27898):    at com.example.free.Add.onCreate(Add.java:167)
09-10 12:14:07.750: E/AndroidRuntime(27898):    at android.app.Activity.performCreate(Activity.java:5104)
09-10 12:14:07.750: E/AndroidRuntime(27898):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
09-10 12:14:07.750: E/AndroidRuntime(27898):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2262)
09-10 12:14:07.750: E/AndroidRuntime(27898):    ... 11 more

这里有什么问题?

谢谢!

修改

多数改变了: 我仍然得到一个Null Pointer exeption ...

CheckoutButton launchSimplePayment = null;
        if (!(ppObj==null))
        launchSimplePayment = ppObj.getCheckoutButton(this, PayPal.BUTTON_278x43, CheckoutButton.TEXT_PAY);

        if (!(launchSimplePayment==null)){
        launchSimplePayment.setOnClickListener(this);   
        layoutSimplePayment.addView(launchSimplePayment);
        mLinLay.addView(layoutSimplePayment);


        setContentView(mLinLay);}

logcat的:

09-10 12:52:51.902: W/dalvikvm(3578): threadid=1: thread exiting with uncaught exception (group=0x41f0a930)
09-10 12:52:51.949: E/AndroidRuntime(3578): FATAL EXCEPTION: main
09-10 12:52:51.949: E/AndroidRuntime(3578): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.free/com.example.free.Add}: java.lang.NullPointerException
09-10 12:52:51.949: E/AndroidRuntime(3578):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2308)
09-10 12:52:51.949: E/AndroidRuntime(3578):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2358)
09-10 12:52:51.949: E/AndroidRuntime(3578):     at android.app.ActivityThread.access$600(ActivityThread.java:153)
09-10 12:52:51.949: E/AndroidRuntime(3578):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1247)
09-10 12:52:51.949: E/AndroidRuntime(3578):     at android.os.Handler.dispatchMessage(Handler.java:99)
09-10 12:52:51.949: E/AndroidRuntime(3578):     at android.os.Looper.loop(Looper.java:137)
09-10 12:52:51.949: E/AndroidRuntime(3578):     at android.app.ActivityThread.main(ActivityThread.java:5227)
09-10 12:52:51.949: E/AndroidRuntime(3578):     at java.lang.reflect.Method.invokeNative(Native Method)
09-10 12:52:51.949: E/AndroidRuntime(3578):     at java.lang.reflect.Method.invoke(Method.java:511)
09-10 12:52:51.949: E/AndroidRuntime(3578):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
09-10 12:52:51.949: E/AndroidRuntime(3578):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
09-10 12:52:51.949: E/AndroidRuntime(3578):     at dalvik.system.NativeStart.main(Native Method)
09-10 12:52:51.949: E/AndroidRuntime(3578): Caused by: java.lang.NullPointerException
09-10 12:52:51.949: E/AndroidRuntime(3578):     at com.paypal.android.MEP.PayPal.getDensity(Unknown Source)
09-10 12:52:51.949: E/AndroidRuntime(3578):     at com.paypal.android.MEP.CheckoutButton.a(Unknown Source)
09-10 12:52:51.949: E/AndroidRuntime(3578):     at com.paypal.android.MEP.PayPal.getCheckoutButton(Unknown Source)
09-10 12:52:51.949: E/AndroidRuntime(3578):     at com.example.free.Add.onCreate(Add.java:169)
09-10 12:52:51.949: E/AndroidRuntime(3578):     at android.app.Activity.performCreate(Activity.java:5104)
09-10 12:52:51.949: E/AndroidRuntime(3578):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
09-10 12:52:51.949: E/AndroidRuntime(3578):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2262)
09-10 12:52:51.949: E/AndroidRuntime(3578):     ... 11 more

第169行是:

launchSimplePayment = ppObj.getCheckoutButton(this, PayPal.BUTTON_278x43, CheckoutButton.TEXT_PAY);

0 个答案:

没有答案