For some reason, every now and then some users receive the following error when they take a photo through our company app. (There's a lot of legacy code I'm still getting my head around.)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4789)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4832)
at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:52)
at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:190)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:105)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2386)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:213)
at android.app.ActivityThread.main(ActivityThread.java:8178)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1101)
Caused by: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=null} to activity {w.h/w.h.main}: java.lang.NullPointerException: Attempt to read from field 'java.lang.String w.h.images.imageFilename' on a null object reference
at android.app.ActivityThread.deliverResults(ActivityThread.java:5471)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4776)
... 11 more
Caused by: java.lang.NullPointerException: Attempt to read from field 'java.lang.String w.h.images.imageFilename' on a null object reference
at w.h.main.onActivityResult(main.java:6931)
at android.app.Activity.dispatchActivityResult(Activity.java:8413)
at android.app.ActivityThread.deliverResults(ActivityThread.java:5464)
... 12 more
We have around 150 users but only a handful who have this issue regularly. I found a handful of strings were being set to null
incorrectly which helped resolve part of the issue however.
It crashes at the following part of onActivityResult
:
// Deal with images once they've been taken
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(resultCode, resultCode, data);
//Check if this is initiated. If not, well, initiate it.
if(appointmentQuestions == null) appointmentQuestions = new appointmentQuestions(this);
if(requestCode == CODE_NON_REPORT && resultCode == RESULT_LOGOUT) {
forceLogout();
} else if(requestCode == images.REQUEST_CAMERA || requestCode == images.REQUEST_VIDEO) {
if (data != null) {
// Build key for corresponding image instance
String key = String.valueOf(apId);
if (activeContentView == R.layout.missed_call) {
key += "_missed_call";
} else if (activeContentView == R.layout.part_collection) {
key += "_part_collection";
} else if (activeContentView == R.layout.transport) {
key += "_transport";
} else {
int currentQuestion = appointmentQuestions.currentQuestionKey();
key += "_q" + currentQuestion;
if (appointmentQuestions.questionType(String.valueOf(currentQuestion)).equals("faultsList")) {
key += "_ftAppCode" + ftAppCode;
}
}
key += "_" + activeMultiSection;
Log.d("~~ key", key);
// Get instance
images instance = imagesInstances.get(key);
Bitmap imageResized = null;
String riDate = String.valueOf(new Timestamp(new Date().getTime()));
String imagePath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS) + "/hs/";
imagePath += instance.imageFilename.endsWith("mp4") ? "videos" : "images";
imagePath += "/" + instance.imageFilename;
I can't seem to find a reason for the instance to return as null
on occasion.