提问人:mobile developer 提问时间:2/28/2020 更新时间:8/3/2020 访问量:175
在 android 中使用 Telr Payment Gateway 时,上下文为 null
Context is null while using Telr Payment Gateway in android
问:
我正在我的应用程序中集成Telr支付网关。我使用了来自那里的虚拟项目的代码,这些代码工作正常,我在我的片段中使用了他们的代码,但它抛出了空上下文错误。我已经尝试了诸如“getContext”,“getApplicationContext”等所有方法,但是向我显示上下文为null的错误
法典:
public void sendMessage() {
Intent intent = new Intent(getActivity(), WebviewActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
intent.putExtra(WebviewActivity.EXTRA_MESSAGE, getMobileRequest());
intent.putExtra(WebviewActivity.SUCCESS_ACTIVTY_CLASS_NAME, "com.marketplace.activity.SuccessTransationActivity");
intent.putExtra(WebviewActivity.FAILED_ACTIVTY_CLASS_NAME, "com.marketplace.activity.FailedTransationActivity");
intent.putExtra(WebviewActivity.IS_SECURITY_ENABLED, isSecurityEnabled);
startActivity(intent);
}
答:
1赞
Bibin Jaimon
8/3/2020
#1
TelrApplication 类中存在一个变量“a”。 使用 TelrApplication 扩展您的应用程序。这将解决您的问题。
public class TelrApplication extends Application {
private static Context a;
public TelrApplication() {
}
public void onCreate() {
super.onCreate();
Log.d("Hany", "Context Started....");
a = this.getApplicationContext();
}
public static Context a() {
return a;
}
}
评论