简体   繁体   English

使用相机后强行关闭

[英]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 . - 我的Camera活动中有一个按钮,可以进入下一个我的OpenurlActivity活动。 but when I click on back button I got this error on my logcat: 但是当我点击后退按钮时,我的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. 您必须检查第510行的变量不为空。

i saw that the method called by onResume, the camera was null 我看到onResume调用的方法,相机为空

Than you have what is the problem, obviously need to initialise the camera before that line and check if initialised. 比你有什么问题,显然需要在该行之前初始化相机并检查是否已初始化。 Maybe at onCreate. 也许在onCreate。

At some point in your code you are setting mCamera to null . 在代码中的某个时刻,您将mCamera设置为null

It could be in your onPause or onStop methods, or even your onStart or onResume methods. 它可能位于onPauseonStop方法中,甚至可能位于onStartonResume方法中。 Review the Activity Lifecycle 查看活动生命周期

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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