0
我試圖獲取條形碼掃描結果,但有時textview
變得null
。掃描結果是在加載片段之前得到的,還是其他問題?在onActivityResult()中查看變空
以下是我的崩潰報告:
Fatal Exception: java.lang.RuntimeException: Unable to resume activity {com.example.infinity.ilfms/com.example.infinity.ilfms.views.material_collected.MaterialCollectedActivity}: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=135123, result=-1, data=Intent { act=com.google.zxing.client.android.SCAN flg=0x80000 (has extras) }} to activity {com.example.infinity.ilfms/com.example.infinity.ilfms.views.material_collected.MaterialCollectedActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.EditText.setText(java.lang.CharSequence)' on a null object reference
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3294)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3325)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2635)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:4313)
at android.app.ActivityThread.-wrap15(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1488)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5736)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:910)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:771)
Caused by java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=135123, result=-1, data=Intent { act=com.google.zxing.client.android.SCAN flg=0x80000 (has extras) }} to activity {com.example.infinity.ilfms/com.example.infinity.ilfms.views.material_collected.MaterialCollectedActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.EditText.setText(java.lang.CharSequence)' on a null object reference
at android.app.ActivityThread.deliverResults(ActivityThread.java:3925)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3276)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3325)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2635)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:4313)
at android.app.ActivityThread.-wrap15(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1488)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5736)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:910)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:771)
Caused by java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.EditText.setText(java.lang.CharSequence)' on a null object reference
at com.example.infinity.ilfms.views.material_collected.MaterialCollectedFragment.refreshViewOnSuccessIfAnyForOthers(MaterialCollectedFragment.java:373)
at com.example.infinity.ilfms.views.base_view.fragements.BaseFragment.onActivityResult(BaseFragment.java:134)
at android.support.v4.app.FragmentActivity.onActivityResult(FragmentActivity.java:164)
at android.app.Activity.dispatchActivityResult(Activity.java:6475)
at android.app.ActivityThread.deliverResults(ActivityThread.java:3921)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3276)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3325)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2635)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:4313)
at android.app.ActivityThread.-wrap15(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1488)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5736)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:910)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:771)
這裏是我的onActivityResult():
@Override
protected void refreshViewOnSuccessIfAnyForOthers(int requestCode, int typeOfImage, Intent data, int resultCode) {
super.refreshViewOnSuccessIfAnyForOthers(requestCode, typeOfImage, data, resultCode);
if (requestCode == 4051) {
if (resultCode == RESULT_OK) {
//get the extras that are returned from the intent
String contents = data.getStringExtra("SCAN_RESULT");
Logger.logError(LOG_TAG,"Barcode result "+contents);
String format = data.getStringExtra("SCAN_RESULT_FORMAT");
if(etRouterCode!=null) {
etRouterCode.setText(contents);
}
}
}
}
你的'onActivityResult'是怎麼樣的? –
請將您的活動代碼發送至 –
@MuratK。我發佈了我的活動代碼 –