我对Android完全陌生。我被要求将paytm集成到客户应用程序。我按照此处给出的步骤进行操作:
https://www.simplifiedcoding.net/paytm-integration-android-example/
我收到一个奇怪的错误,不确定如何解决,我还从上述网站下载了源代码,它也给我同样的错误。
06-20 20:04:07.575 24839-24839/simplifiedcoding.net.paytmpaymentsample E/AndroidRuntime: FATAL EXCEPTION: main
Process: simplifiedcoding.net.paytmpaymentsample, PID: 24839
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String simplifiedcoding.net.paytmpaymentsample.Checksum.getChecksumHash()' on a null object reference
at simplifiedcoding.net.paytmpaymentsample.MainActivity$2.onResponse(MainActivity.java:95)
at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run(ExecutorCallAdapterFactory.java:68)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6753)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:482)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
06-20 20:04:07.592 24839-25361/simplifiedcoding.net.paytmpaymentsample D/OSTracker: OS Event: crash
06-20 20:04:07.666 24839-25361/simplifiedcoding.net.paytmpaymentsample D/AbstractTracker: Event success
以下是使用的代码:
String txnAmount = textViewPrice.getText().toString().trim();
//creating a retrofit object.
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(Api.BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
//creating the retrofit api service
Api apiService = retrofit.create(Api.class);
//creating paytm object
//containing all the values required
final Paytm paytm = new Paytm(
Constants.M_ID,
Constants.CHANNEL_ID,
txnAmount,
Constants.WEBSITE,
Constants.CALLBACK_URL,
Constants.INDUSTRY_TYPE_ID
);
//creating a call object from the apiService
Call<Checksum> call = apiService.getChecksum(
paytm.getmId(),
paytm.getOrderId(),
paytm.getCustId(),
paytm.getChannelId(),
paytm.getTxnAmount(),
paytm.getWebsite(),
paytm.getCallBackUrl(),
paytm.getIndustryTypeId()
);
//making the call to generate checksum
call.enqueue(new Callback<Checksum>() {
@Override
public void onResponse(Call<Checksum> call, Response<Checksum> response) {
//once we get the checksum we will initiailize the payment.
//the method is taking the checksum we got and the paytm object as the parameter
**I am getting an error from below line:**
initializePaytmPayment(response.body().getChecksumHash(), paytm);
}
@Override
public void onFailure(Call<Checksum> call, Throwable t) {
}
});
怎么了?
答案 0 :(得分:0)
根据错误日志,您的apiService变量为null,并且您正在尝试对其调用方法(getChecksum)。在声明了apiService变量的行上放置调试指针,并检查其值是否为null。如果为null,请尝试找出原因。大部分可能的外部api(如paytm)都需要OAuth验证,您可能会错过了。