Uncaught handler with surfaceview

Put your problem here if it does not fit any of the other categories.

Uncaught handler with surfaceview

Postby tinyang » Sun Aug 23, 2009 3:00 pm

Hello.

I have an activity which calls the camera preview which works fine until I try to close the camera preview and go back to previous screen/another activity. I have coded the arrow/back key on the phone to close the preview, and release the camera, but I still get this error and I don't understand why. I've narrowed it down to the problem seems to be happening at cam.stopPreview(), but I don't know how to fix the problem. Can anyone help?

Here is my applicable code:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. public void surfaceDestroyed(SurfaceHolder holder) {
  3.  
  4.         // Surface will be destroyed when we return, so stop the preview.
  5.  
  6.         // Because the CameraDevice object is not a shared resource, it's very
  7.  
  8.         // important to release it when the activity is paused.
  9.  
  10.                 cam.stopPreview();
  11.  
  12.                 cam = null;
  13.  
  14.                 cam.release();
  15.  
  16.         }
  17.  
  18.  
  19.  
  20. @Override
  21.  
  22.     //Make back/arrow button on phone a go back to main menu
  23.  
  24.     public boolean onKeyDown(int keyCode, KeyEvent event) {
  25.  
  26.         if ((keyCode == KeyEvent.KEYCODE_BACK)) {
  27.  
  28.                 cam.stopPreview();
  29.  
  30.                 cam = null;
  31.  
  32.                 cam.release();
  33.  
  34.                 return true;
  35.  
  36.         } else {
  37.  
  38.                 return false;
  39.  
  40.         }
  41.  
  42.     }
  43.  
  44.  
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


Below is the output from the logcat:

08-22 21:34:11.913: ERROR/AndroidRuntime(329): Uncaught handler: thread main exiting due to uncaught exception
08-22 21:34:11.933: ERROR/AndroidRuntime(329): java.lang.NullPointerException
08-22 21:34:11.933: ERROR/AndroidRuntime(329): at net.tinyang.app.TakePic$Preview.surfaceDestroyed(TakePic.java:72)
08-22 21:34:11.933: ERROR/AndroidRuntime(329): at android.view.SurfaceView.reportSurfaceDestroyed(SurfaceView.java:381)
08-22 21:34:11.933: ERROR/AndroidRuntime(329): at android.view.SurfaceView.updateWindow(SurfaceView.java:316)
08-22 21:34:11.933: ERROR/AndroidRuntime(329): at android.view.SurfaceView.onWindowVisibilityChanged(SurfaceView.java:173)
08-22 21:34:11.933: ERROR/AndroidRuntime(329): at android.view.View.dispatchWindowVisibilityChanged(View.java:3261)
08-22 21:34:11.933: ERROR/AndroidRuntime(329): at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:691)
08-22 21:34:11.933: ERROR/AndroidRuntime(329): at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:691)
08-22 21:34:11.933: ERROR/AndroidRuntime(329): at android.view.ViewRoot.performTraversals(ViewRoot.java:587)
08-22 21:34:11.933: ERROR/AndroidRuntime(329): at android.view.ViewRoot.handleMessage(ViewRoot.java:1103)
08-22 21:34:11.933: ERROR/AndroidRuntime(329): at android.os.Handler.dispatchMessage(Handler.java:88)
08-22 21:34:11.933: ERROR/AndroidRuntime(329): at android.os.Looper.loop(Looper.java:123)
08-22 21:34:11.933: ERROR/AndroidRuntime(329): at android.app.ActivityThread.main(ActivityThread.java:3739)
08-22 21:34:11.933: ERROR/AndroidRuntime(329): at java.lang.reflect.Method.invokeNative(Native Method)
08-22 21:34:11.933: ERROR/AndroidRuntime(329): at java.lang.reflect.Method.invoke(Method.java:515)
08-22 21:34:11.933: ERROR/AndroidRuntime(329): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
08-22 21:34:11.933: ERROR/AndroidRuntime(329): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:497)
08-22 21:34:11.933: ERROR/AndroidRuntime(329): at dalvik.system.NativeStart.main(Native Method)
--
Moderation is the key to happiness and harmony in one's life.
User avatar
tinyang
Freshman
Freshman
 
Posts: 6
Joined: Sat Jan 03, 2009 4:50 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: MSNbot Media and 18 guests