android camera hardware does not open

lordwindom

New Member
i'm trying to open the camera using the following code but the app crashs and the logcat generate the below mentione error. I also posted the contents of the xml file as the logcat says that the width of the layout is not specified but it is already defined in the xml fileJava Code:\[code\]SurfaceView camerPreview;SurfaceHolder previewHolder;Camera camera;Boolean inPreview;Callback surfaceCallback = new Callback() { public void surfaceDestroyed(SurfaceHolder holder) { // TODO Auto-generated method stub camera.stopPreview(); camera.release(); camera = null; } public void surfaceCreated(SurfaceHolder holder) { // TODO Auto-generated method stub try { //Open The Camera camera = android.hardware.Camera.open(); camera.setPreviewDisplay(holder); } catch(IOException ioe) { ioe.printStackTrace(System.out); } } public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { // TODO Auto-generated method stub android.hardware.Camera.Parameters parameters = camera.getParameters(); parameters.setSceneMode(parameters.SCENE_MODE_SPORTS); //parameters.setFlashMode(parameters.FLASH_MODE_AUTO); parameters.setPreviewSize(width/2, height/2); parameters.setPictureSize(width/2, height/2); camera.setParameters(parameters); camera.startPreview(); }};@Overridepublic void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_aug_real_test); //getActionBar().setDisplayHomeAsUpEnabled(true); camerPreview = (SurfaceView) findViewById(R.id.cameraPreview); previewHolder = camerPreview.getHolder(); previewHolder.addCallback((android.view.SurfaceHolder.Callback) surfaceCallback); previewHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);}\[/code\]}LogCat:\[code\]09-17 12:41:16.867: E/AndroidRuntime(6726): FATAL EXCEPTION: main09-17 12:41:16.867: E/AndroidRuntime(6726): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.augrealtest/com.example.augrealtest.AugRealTest}: java.lang.RuntimeException: Binary XML file line #2: You must supply a layout_width attribute.09-17 12:41:16.867: E/AndroidRuntime(6726): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1968)09-17 12:41:16.867: E/AndroidRuntime(6726): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1993)09-17 12:41:16.867: E/AndroidRuntime(6726): at android.app.ActivityThread.access$600(ActivityThread.java:127)09-17 12:41:16.867: E/AndroidRuntime(6726): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1159)09-17 12:41:16.867: E/AndroidRuntime(6726): at android.os.Handler.dispatchMessage(Handler.java:99)09-17 12:41:16.867: E/AndroidRuntime(6726): at android.os.Looper.loop(Looper.java:137)09-17 12:41:16.867: E/AndroidRuntime(6726): at android.app.ActivityThread.main(ActivityThread.java:4507)09-17 12:41:16.867: E/AndroidRuntime(6726): at java.lang.reflect.Method.invokeNative(Native Method)09-17 12:41:16.867: E/AndroidRuntime(6726): at java.lang.reflect.Method.invoke(Method.java:511)09-17 12:41:16.867: E/AndroidRuntime(6726): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)09-17 12:41:16.867: E/AndroidRuntime(6726): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)09-17 12:41:16.867: E/AndroidRuntime(6726): at dalvik.system.NativeStart.main(Native Method)09-17 12:41:16.867: E/AndroidRuntime(6726): Caused by: java.lang.RuntimeException: Binary XML file line #2: You must supply a layout_width attribute.09-17 12:41:16.867: E/AndroidRuntime(6726): at android.content.res.TypedArray.getLayoutDimension(TypedArray.java:491)09-17 12:41:16.867: E/AndroidRuntime(6726): at android.view.ViewGroup$LayoutParams.setBaseAttributes(ViewGroup.java:5318)09-17 12:41:16.867: E/AndroidRuntime(6726): at android.view.ViewGroup$MarginLayoutParams.<init>(ViewGroup.java:5439)09-17 12:41:16.867: E/AndroidRuntime(6726): at android.widget.FrameLayout$LayoutParams.<init>(FrameLayout.java:580)09-17 12:41:16.867: E/AndroidRuntime(6726): at android.widget.FrameLayout.generateLayoutParams(FrameLayout.java:537)09-17 12:41:16.867: E/AndroidRuntime(6726): at android.widget.FrameLayout.generateLayoutParams(FrameLayout.java:54)09-17 12:41:16.867: E/AndroidRuntime(6726): at android.view.LayoutInflater.inflate(LayoutInflater.java:477)09-17 12:41:16.867: E/AndroidRuntime(6726): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)09-17 12:41:16.867: E/AndroidRuntime(6726): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)09-17 12:41:16.867: E/AndroidRuntime(6726): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:271)09-17 12:41:16.867: E/AndroidRuntime(6726): at android.app.Activity.setContentView(Activity.java:1835)09-17 12:41:16.867: E/AndroidRuntime(6726): at com.example.augrealtest.AugRealTest.onCreate(AugRealTest.java:57)09-17 12:41:16.867: E/AndroidRuntime(6726): at android.app.Activity.performCreate(Activity.java:4465)09-17 12:41:16.867: E/AndroidRuntime(6726): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1052)09-17 12:41:16.867: E/AndroidRuntime(6726): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1932)\[/code\]XML:\[code\]<?xml version="1.0" encoding="utf-8"?><SurfaceViewxmlns:android="http://schemas.android.com/pak/res/android"android:id="@+id/cameraPreview"android:layout_width="fill_parent"android:layout_height="fill_parent"></SurfaceView>\[/code\]
 
Back
Top