Use adb logcat, DDMS, or the DDMS perspective in Eclipse to examine the Java stack trace associated with your error.
On Wed, Aug 18, 2010 at 12:11 AM, Chris Maurer <[email protected]> wrote: > I have a HTC Incredible and I'm trying to write a simple application > to take a picture and save it on the SD card. When I run the tutorial > at http://github.com/commonsguy/cw-advandroid/tree/master/Camera/Picture > it works fine in the emulator. However, when I try and test it on my > phone I get "The application Picture Demo (process > com.commonsware.android.camera) has stopped unexpectedly. Please try > again." > > I have set the following permissions in the AndroidManifest file. > > <uses-feature android:name="android.hardware.camera" /> > <uses-permission android:name="android.permission.CAMERA" /> > <uses-permission > android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> > > > Below is the code I am using. > > > import android.app.Activity; > import android.graphics.PixelFormat; > import android.hardware.Camera; > import android.os.AsyncTask; > import android.os.Bundle; > import android.os.Environment; > import android.util.Log; > import android.view.KeyEvent; > import android.view.SurfaceHolder; > import android.view.SurfaceView; > import android.widget.Toast; > import java.io.File; > import java.io.FileOutputStream; > > public class PictureDemo extends Activity { > private SurfaceView preview=null; > private SurfaceHolder previewHolder=null; > private Camera camera=null; > > �...@override > public void onCreate(Bundle savedInstanceState) { > super.onCreate(savedInstanceState); > setContentView(R.layout.main); > > preview=(SurfaceView)findViewById(R.id.preview); > previewHolder=preview.getHolder(); > previewHolder.addCallback(surfaceCallback); > previewHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); > } > > �...@override > public boolean onKeyDown(int keyCode, KeyEvent event) { > if (keyCode==KeyEvent.KEYCODE_CAMERA || > keyCode==KeyEvent.KEYCODE_SEARCH) { > takePicture(); > > return(true); > } > > return(super.onKeyDown(keyCode, event)); > } > > private void takePicture() { > camera.takePicture(null, null, photoCallback); > } > > SurfaceHolder.Callback surfaceCallback=new SurfaceHolder.Callback() { > public void surfaceCreated(SurfaceHolder holder) { > camera=Camera.open(); > > try { > camera.setPreviewDisplay(previewHolder); > } > catch (Throwable t) { > Log.e("PictureDemo-surfaceCallback", > "Exception in > setPreviewDisplay()", t); > Toast > .makeText(PictureDemo.this, > t.getMessage(), Toast.LENGTH_LONG) > .show(); > } > } > > public void surfaceChanged(SurfaceHolder holder, > > int format, int width, > > int height) { > Camera.Parameters parameters=camera.getParameters(); > > parameters.setPreviewSize(width, height); > parameters.setPictureFormat(PixelFormat.JPEG); > > camera.setParameters(parameters); > camera.startPreview(); > } > > public void surfaceDestroyed(SurfaceHolder holder) { > camera.stopPreview(); > camera.release(); > camera=null; > } > }; > > Camera.PictureCallback photoCallback=new Camera.PictureCallback() { > public void onPictureTaken(byte[] data, Camera camera) { > new SavePhotoTask().execute(data); > camera.startPreview(); > } > }; > > class SavePhotoTask extends AsyncTask<byte[], String, String> { > �...@override > protected String doInBackground(byte[]... jpeg) { > File photo=new > File(Environment.getExternalStorageDirectory(), > > "photo.jpg"); > > if (photo.exists()) { > photo.delete(); > } > > try { > FileOutputStream fos=new > FileOutputStream(photo.getPath()); > > fos.write(jpeg[0]); > fos.close(); > } > catch (java.io.IOException e) { > Log.e("PictureDemo", "Exception in > photoCallback", e); > } > > return(null); > } > } > } > > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected] > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en > -- Mark Murphy (a Commons Guy) http://commonsware.com | http://github.com/commonsguy http://commonsware.com/blog | http://twitter.com/commonsguy _The Busy Coder's Guide to Android Development_ Version 3.1 Available! -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

