我只想使用柑橘支付集成,当我点击立即购买按钮时,它会出现错误,我的应用程序已经崩溃,主要是错误出现在 CheckUserLogin 和 checkuserlogin 方法中。我不明白如何解决这个问题?
错误
java.lang.NullPointerException: Attempt to invoke virtual method 'void com.citrus.sdk.network.e.d()' on a null object reference
at com.citrus.sdk.e.d(Unknown Source)
at com.citrus.sdk.CitrusClient.signOut(Unknown Source)
at com.citrus.sdk.CitrusClient$15.error(Unknown Source)
at com.citrus.sdk.e.a(Unknown Source)
at com.citrus.sdk.e.a(Unknown Source)
at com.citrus.sdk.e$1.error(Unknown Source)
at com.citrus.sdk.e.a(Unknown Source)
at com.citrus.sdk.e.a(Unknown Source)
at com.citrus.sdk.e.b(Unknown Source)
at com.citrus.sdk.CitrusClient.getPrepaidToken(Unknown Source)
at com.citrus.sdk.CitrusClient.isUserSignedIn(Unknown Source)
at com.codeexpertise.eshop.startup.PayPalCheckoutActivity.checkUserLogin(PayPalCheckoutActivity.java:85)
at com.codeexpertise.eshop.startup.PayPalCheckoutActivity.onResume(PayPalCheckoutActivity.java:81)
贝宝结帐活动。java(这是声明 checkuserlogin 方法的 java 文件,并在错误中显示 checkuserlogin 中的错误)
public class PayPalCheckoutActivity extends Fragment implements View.OnClickListener {
private TextView textMessage = null;
private CitrusClient citrusClient = null;
private Button btnSignout = null;
private Button btnUserManagement = null;
private Button btnWalletPayment = null;
public boolean isUserLoggedIn = false;
public PayPalCheckoutActivity() {
}
public static PayPalCheckoutActivity newInstance() {
return new PayPalCheckoutActivity();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_ui, container, false);
textMessage = (TextView) rootView.findViewById(R.id.txt_message);
btnUserManagement = (Button) rootView.findViewById(R.id.btn_user_management);
btnWalletPayment = (Button) rootView.findViewById(R.id.btn_user_wallet);
btnSignout = (Button) rootView.findViewById(R.id.btn_logout);
btnSignout.setOnClickListener(this);
return rootView;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
citrusClient = CitrusClient.getInstance(getActivity());
}
@Override
public void onClick(View v) {
citrusClient.signOut(new Callback<CitrusResponse>() {
@Override
public void success(CitrusResponse citrusResponse) {
((UIActivity) getActivity()).showSnackBar(citrusResponse.getMessage());
textMessage.setText("Please Sign In or Sign Up the user.");
btnSignout.setVisibility(View.GONE);
btnUserManagement.setVisibility(View.VISIBLE);
btnWalletPayment.setVisibility(View.GONE);
}
@Override
public void error(CitrusError error) {
((UIActivity) getActivity()).showSnackBar(error.getMessage());
}
});
}
@Override
public void onResume() {
super.onResume();
checkUserLogin();
}
void checkUserLogin() {
citrusClient.isUserSignedIn(new Callback<Boolean>() {
@Override
public void success(Boolean isUserLoggedIn) {
PayPalCheckoutActivity.this.isUserLoggedIn = isUserLoggedIn;
if (isUserLoggedIn) {
citrusClient.getProfileInfo(new Callback<CitrusUser>() {
@Override
public void success(CitrusUser citrusUser) {
textMessage.setText("Welcome " + citrusUser.getEmailId());
btnWalletPayment.setVisibility(View.VISIBLE);
btnUserManagement.setVisibility(View.GONE);
btnSignout.setVisibility(View.VISIBLE);
}
@Override
public void error(CitrusError error) {
textMessage.setText("Welcome Back");
btnWalletPayment.setVisibility(View.VISIBLE);
btnUserManagement.setVisibility(View.GONE);
btnSignout.setVisibility(View.VISIBLE);
}
});
} else {
textMessage.setText("Please Sign In or Sign Up the user.");
btnWalletPayment.setVisibility(View.GONE);
btnUserManagement.setVisibility(View.VISIBLE);
btnSignout.setVisibility(View.GONE);
}
}
@Override
public void error(CitrusError error) {
textMessage.setText(error.getMessage());
}
});
}
}