I have an app that uses google mobile vision(OCR), Camera and Flashlight, lately i keep getting crashes report almost everyday on Android 6.0 Devices.
here's the report :
java.lang.IllegalStateException:
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick (AppCompatViewInflater.java:293)
at android.view.View.performClick (View.java:5293)
at android.view.View$PerformClick.run (View.java:21660)
at android.os.Handler.handleCallback (Handler.java:815)
at android.os.Handler.dispatchMessage (Handler.java:104)
at android.os.Looper.loop (Looper.java:227)
at android.app.ActivityThread.main (ActivityThread.java:6100)
at java.lang.reflect.Method.invoke (Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:859)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:749)
Caused by: java.lang.reflect.InvocationTargetException:
at java.lang.reflect.Method.invoke (Native Method)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick (AppCompatViewInflater.java:288)
Caused by: java.lang.NullPointerException:
at java.lang.reflect.Field.get (Native Method)
at myPacName.instantscanandrecharge.CamActivity.changeFlashStatus (CamActivity.java:412)
i don't know what to do with the native method in this report
but from my own code the method that causes this error is :
public void changeFlashStatus(View v) {
Field[] declaredFields = CameraSource.class.getDeclaredFields();
for (Field field : declaredFields) {
if (field.getType() == Camera.class) {
field.setAccessible(true);
try {
camera = (Camera) field.get(camSource);
if (camera != null) {
params = camera.getParameters();
if(!isFlash){
params.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
flash_btn.setImageResource(R.drawable.ic_action_flash_on);
isFlash = true;
} else {
params.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
flash_btn.setImageResource(R.drawable.ic_action_flash_off);
isFlash = false;
}
camera.setParameters(params);
}
} catch (IllegalAccessException e) {
e.printStackTrace();
}
break;
}
}
}
why it's not working with Android 6.0 ?