gpt4 book ai didi

android - 在 android.support.v4.app.Fragment.onActivityResult(int, int, android.content.Intent) 获取 NullPointerException

转载 作者:行者123 更新时间:2023-11-29 18:45:34 26 4
gpt4 key购买 nike

我正在使用 NSDL Esign 门户通过生物识别设备验证 Aadhar 详细信息。指纹数据已成功扫描,但不幸的是,在该过程结束时,我的应用程序因上述错误而崩溃。这是我在 Activity 中实现的

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
for (Fragment fragment : getSupportFragmentManager().getFragments()) {
fragment.onActivityResult(requestCode, resultCode, data);
}
}

这是我在 fragment 中添加的代码,用于将指纹数据添加到我的服务器中。

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case Constants.NSDL_REQUEST_CODE:
if (resultCode == RESULT_OK && null != data) {
String eSignResponse = data.getStringExtra("signedResponse");
try {
String postData = "msg=" + URLEncoder.encode(eSignResponse, "UTF-8") + "&type=M";
webView.postUrl(responseURL, postData.getBytes("UTF-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
break;
}
}

LogCat 中发生的错误是

java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=100, result=-1, data=Intent { (has extras) }} to activity {com.fin.esign/com.fin.esign.BaseActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v4.app.Fragment.onActivityResult(int, int, android.content.Intent)' on a null object reference
at android.app.ActivityThread.deliverResults(ActivityThread.java:4255)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4298)
at android.app.ActivityThread.-wrap20(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1613)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:203)
at android.app.ActivityThread.main(ActivityThread.java:6339)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1084)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:945)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v4.app.Fragment.onActivityResult(int, int, android.content.Intent)' on a null object reference
at com.fin.esign.BaseActivity.onActivityResult(BaseActivity.java:122)
at android.app.Activity.dispatchActivityResult(Activity.java:6948)
at android.app.ActivityThread.deliverResults(ActivityThread.java:4251)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4298) 
at android.app.ActivityThread.-wrap20(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1613) 
at android.os.Handler.dispatchMessage(Handler.java:110) 
at android.os.Looper.loop(Looper.java:203) 
at android.app.ActivityThread.main(ActivityThread.java:6339) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1084) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:945) 

最佳答案

我通过添加删除 fragment 的 for 循环并简单地在我愿意接收结果的地方添加我的特定 fragment 来解决这个问题。

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
for (Fragment fragment : getSupportFragmentManager().getFragments()) {
if (null != fragment) {
fragment.onActivityResult(requestCode, resultCode, data);
} else {
new MyFragment().onActivityResult(requestCode, resultCode, data);
}
}
}

关于android - 在 android.support.v4.app.Fragment.onActivityResult(int, int, android.content.Intent) 获取 NullPointerException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52097693/

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