1

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

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

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

在 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);

点击:

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

日志猫:

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

这里有什么问题?

谢谢!

编辑

这就是我改变的:我仍然得到空指针异常......

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

日志猫:

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

0 回答 0