简体   繁体   中英

Force close after using camera

kindly help me to solve this problem I am unable to resume my activity once I get to the camera activity. - I have a button in my Camera activity to go to the next activity which is my OpenurlActivity . but when I click on back button I got this error on my logcat:

 08-15 17:49:55.518: E/AndroidRuntime(13628): FATAL EXCEPTION: main
 08-15 17:49:55.518: E/AndroidRuntime(13628): java.lang.RuntimeException: Unable to 
 resume activity {com.example.qrreader/com.example.qrreader.CameraTestActivity}:     
  java.lang.NullPointerException
 08-15 17:49:55.518: E/AndroidRuntime(13628):   at  
 android.app.ActivityThread.performResumeActivity(ActivityThread.java:2825)
 08-15 17:49:55.518: E/AndroidRuntime(13628):   at 
  android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2854)
  08-15 17:49:55.518: E/AndroidRuntime(13628):  at    
  android.app.ActivityThread$H.handleMessage(ActivityThread.java:1323)
 08-15 17:49:55.518: E/AndroidRuntime(13628):   at 
 android.os.Handler.dispatchMessage(Handler.java:99)
 08-15 17:49:55.518: E/AndroidRuntime(13628):   at 
 android.os.Looper.loop(Looper.java:137)
08-15 17:49:55.518: E/AndroidRuntime(13628):    at 
android.app.ActivityThread.main(ActivityThread.java:5293)
08-15 17:49:55.518: E/AndroidRuntime(13628):    at 
java.lang.reflect.Method.invokeNative(Native Method)
08-15 17:49:55.518: E/AndroidRuntime(13628):    at 
java.lang.reflect.Method.invoke(Method.java:511)
08-15 17:49:55.518: E/AndroidRuntime(13628):    at  
 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
08-15 17:49:55.518: E/AndroidRuntime(13628):    at 
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
 08-15 17:49:55.518: E/AndroidRuntime(13628):   at 
dalvik.system.NativeStart.main(Native Method)
08-15 17:49:55.518: E/AndroidRuntime(13628): Caused by: java.lang.NullPointerException
08-15 17:49:55.518: E/AndroidRuntime(13628):    at 
com.example.qrreader.CameraTestActivity.onResume(CameraTestActivity.java:510)
08-15 17:49:55.518: E/AndroidRuntime(13628):    at 
android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1202)
08-15 17:49:55.518: E/AndroidRuntime(13628):    at 
android.app.Activity.performResume(Activity.java:5328)
08-15 17:49:55.518: E/AndroidRuntime(13628):    at 
android.app.ActivityThread.performResumeActivity(ActivityThread.java:2815)
08-15 17:49:55.518: E/AndroidRuntime(13628):    ... 10 more

Why has this error occurred?

08-15 17:49:55.518: E/AndroidRuntime(13628): Caused by: java.lang.NullPointerException
08-15 17:49:55.518: E/AndroidRuntime(13628):    at 
com.example.qrreader.CameraTestActivity.onResume(CameraTestActivity.java:510)

You have to check a variable at row 510 to not be null.

i saw that the method called by onResume, the camera was null

Than you have what is the problem, obviously need to initialise the camera before that line and check if initialised. Maybe at onCreate.

At some point in your code you are setting mCamera to null .

It could be in your onPause or onStop methods, or even your onStart or onResume methods. Review the Activity Lifecycle

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM