initWithAppID 命令崩溃

发布于 2024-12-01 16:00:58 字数 364 浏览 0 评论 0原文

我是 Android 编程新手,尤其是 PayPal。我有一个负责进行故障排除的应用程序 - 尽管是 Android 新手,但在这一行崩溃了:

initWithAppID(this.getBaseContext(), appID, PayPal.ENV_SANDBOX);

首先,PayPal .ENV_SANDBOX 总是返回 0,我不确定它是否应该返回。其次,为什么总是崩溃?我在网上搜索了原因,人们说是因为它没有完全初始化,这就是它失败的原因。现在我想知道如果我无法初始化这个库我需要做什么?

我正在使用 Eclipse IDE,在 Samsung Galaxy Tab Android 2.2 上进行测试

I am new with Android programming and especially with PayPal. I got an application that was tasked to troubleshoot - despite being new to Android, is crashing at this line:

initWithAppID(this.getBaseContext(), appID, PayPal.ENV_SANDBOX);

Firstly, PayPal.ENV_SANDBOX always returns a 0 which I am not sure if its suppose to. Secondly, why is it always crashing there? I have searched online for the reason, people says its because it did not fully initialized thats why its failing. Now I would like to know what I need to do if I cant initialize this library?

I am using Eclipse IDE, testing on a Samsung Galaxy Tab Android 2.2

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

旧故 2024-12-08 16:00:58

不知道这是否有帮助,但这就是我在使用 PayPal.ENV_NONE 进行测试时修复它的方法(来自 https://github.com/phonegap/phonegap-plugins/blob/master/Android/PayPalPlugin/src/com/phonegap/plugin/mpl.java

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

然后在创建按钮时:

PayPal pp = PayPal.getInstance();
CheckoutButton cb = pp.getCheckoutButton(
        getBaseContext(), 
        PayPal.BUTTON_194x37, 
        CheckoutButton.TEXT_PAY);
cb.setOnClickListener(new OnClickListener() {
    PayPalPayment payment = new PayPalPayment();
    // set subtotal etc ...
    Intent i = PayPal.getInstance().checkout(payment,getApplicationContext());
    startActivityForResult(i, 1);
});

希望能有所帮助

Don't know if this will help but this is how I fixed it while testing with PayPal.ENV_NONE (from https://github.com/phonegap/phonegap-plugins/blob/master/Android/PayPalPlugin/src/com/phonegap/plugin/mpl.java)

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

Then when creating the button:

PayPal pp = PayPal.getInstance();
CheckoutButton cb = pp.getCheckoutButton(
        getBaseContext(), 
        PayPal.BUTTON_194x37, 
        CheckoutButton.TEXT_PAY);
cb.setOnClickListener(new OnClickListener() {
    PayPalPayment payment = new PayPalPayment();
    // set subtotal etc ...
    Intent i = PayPal.getInstance().checkout(payment,getApplicationContext());
    startActivityForResult(i, 1);
});

Hope that helps somehow

葬﹪忆之殇 2024-12-08 16:00:58

您能否指定有关此方法的更多信息?这是贝宝库方法吗?
我认为 PayPal.ENV_SANDBOX 是您必须设置的一些环境变量。顾名思义,此设置用于测试目的或用于开发(实际上不进行任何付款)。
我想您可能会在库文档中找到有关此方法的更多信息。
第二个问题是,你使用了正确的appId吗?基本上下文是正确使用的上下文吗?也许您必须使用 getApplicationContext,请参阅此处此处

Can you specifiy more information about this method? Is it a paypal library method?
I think the PayPal.ENV_SANDBOX is some environment variable you have to set. The name suggests that this settings is used for testing purposes or for developing (not actually doing any payments).
I think you might find out more about this method in the library documentation.
A second question is, have you used the right appId? And is the base context the right context to use? Maybe you have to use the getApplicationContext, see here and here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文