gpt4 book ai didi

java - 尝试集成 Stripe 时应用强制关闭

转载 作者:行者123 更新时间:2023-11-30 00:44:56 25 4
gpt4 key购买 nike

我正在尝试集成 Stripe 以在我的 Android 应用程序中处理付款。

我让用户输入信用卡信息,然后我现在要做的就是创建一个 token 。但是,当我单击该按钮时,应用会强制关闭。

这不是最终应用程序接受卡片和与 Stripe 一起工作的方式,但我只是想了解我将如何在未来集成 Stripe

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.Spinner;
import android.widget.Toast;

import com.stripe.android.*;
import com.stripe.android.model.Card;
import com.stripe.android.model.Token;
import com.stripe.android.Stripe;

import java.util.HashMap;
import java.util.Map;

public class newUser extends AppCompatActivity {

String fname;
String lname;
String email;
String phonenum;
String pin;
String cardNumber;
String cardCVC;
Integer cardExpMonth;
Integer cardExpYear;
String stripetok;
Card cardNew;

private static final String PUBLISHABLE_KEY = "pk_test_iUVdhdvJuurqSxIlXpzq32LS";
UserDBHelper newUserr;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_new_user);

newUserr = new UserDBHelper(newUser.this);

EditText fNameh = (EditText) findViewById(R.id.fNameNew);
EditText lNameh = (EditText) findViewById(R.id.lNameNew);
EditText emailh = (EditText) findViewById(R.id.emailNew);
EditText phoneNumh = (EditText) findViewById(R.id.phoneNew);
EditText pinh = (EditText) findViewById(R.id.pinNew);
EditText cardNumberh = (EditText) findViewById(R.id.cardNumNew);
EditText cardCVCh = (EditText) findViewById(R.id.cvcNew);
Spinner cardExpMonthh = (Spinner) findViewById(R.id.monthNew);
Spinner cardExpYearh = (Spinner) findViewById(R.id.yearNew);

fname = fNameh.getText().toString();
lname = lNameh.getText().toString();
email = emailh.getText().toString();
phonenum = phoneNumh.getText().toString();
pin = pinh.getText().toString();
cardNumber = cardNumberh.getText().toString();
cardCVC = cardCVCh.getText().toString();
cardExpMonth = (Integer) cardExpMonthh.getSelectedItem();
cardExpYear = (Integer) cardExpYearh.getSelectedItem();


cardNew = new Card(
cardNumber,
cardExpMonth,
cardExpYear,
cardCVC
);

ImageButton createNewUser = (ImageButton) findViewById(R.id.createNew);



createNewUser.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{
if(cardNew.validateCard() & cardNew.validateCVC()) {
Stripe stripe = new Stripe();
stripe.createToken(cardNew, PUBLISHABLE_KEY, new TokenCallback() {
public void onSuccess(Token token) {
// TODO: Send Token information to your backend to initiate a charge
Toast.makeText(
getApplicationContext(),
"Token created: " + token.getId(),
Toast.LENGTH_LONG).show();
}

public void onError(Exception error) {
Log.d("Stripe", error.getLocalizedMessage());
}
});

}

else{
Toast.makeText(
getApplicationContext(),
"Token not made!",
Toast.LENGTH_LONG).show();
}

}
});

关于为什么会发生这种情况的任何想法?我没有收到任何错误,但 Activity 甚至不会加载。

我已经包含了

compile 'com.stripe:stripe-android:2.0.2'

在依赖项下进入应用程序的build.gradle

感谢任何输入!

编辑 1:我认为问题可能出在我从微调器将字符串转换为整数时。

E/dalvikvm: Could not find class 'android.widget.ThemedSpinnerAdapter', referenced from method android.support.v7.widget.AppCompatSpinner$DropDownAdapter.<init>
W/dalvikvm: VFY: unable to resolve instanceof 2583 (Landroid/widget/ThemedSpinnerAdapter;) in Landroid/support/v7/widget/AppCompatSpinner$DropDownAdapter;
D/dalvikvm: VFY: replacing opcode 0x20 at 0x0016
D/AndroidRuntime: Shutting down VM
W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x416fcbc0)
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.zeuspwr.zeuspower, PID: 32121
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.zeuspwr.zeuspower/com.zeuspwr.zeuspower.newUser}: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2429)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2493)
at android.app.ActivityThread.access$800(ActivityThread.java:166)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1283)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5584)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
at com.zeuspwr.zeuspower.newUser.onCreate(newUser.java:62)
at android.app.Activity.performCreate(Activity.java:5447)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2393)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2493) 
at android.app.ActivityThread.access$800(ActivityThread.java:166) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1283) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:136) 
at android.app.ActivityThread.main(ActivityThread.java:5584) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:515) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084) 
at dalvik.system.NativeStart.main(Native Method) 
I/Process: Sending signal. PID: 32121 SIG: 9
Application terminated.

最佳答案

改变

cardExpMonth = (Integer) cardExpMonthh.getSelectedItem();
cardExpYear = (Integer) cardExpYearh.getSelectedItem();

cardExpMonth = Integer.valueOf(cardExpMonthh.getSelectedItem());
cardExpYear = Integer.valueOf(cardExpYearh.getSelectedItem());

关于java - 尝试集成 Stripe 时应用强制关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41972154/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com