Camera Problem --> unable to save photos


#1

There is a problem in capturing the picture,I copied the same code as in text book but it is not working…
Am getting following warnings in logcat

[ul]
02-06 12:29:10.762: W/dalvikvm(3643): VFY: unable to resolve virtual method 759: Landroid/support/v4/app/FragmentActivity;.getActionBar ()Landroid/app/ActionBar;
02-06 12:29:10.772: W/dalvikvm(3643): VFY: unable to resolve virtual method 759: Landroid/support/v4/app/FragmentActivity;.getActionBar ()Landroid/app/ActionBar;
02-06 12:29:10.942: I/ActivityThread(3643): queueIdle
02-06 12:29:10.942: W/ActivityNative(3643): send ACTIVITY_IDLE_TRANSACTION
02-06 12:29:14.132: W/dalvikvm(3643): VFY: unable to resolve virtual method 759: Landroid/support/v4/app/FragmentActivity;.getActionBar ()Landroid/app/ActionBar;
02-06 12:29:14.142: W/dalvikvm(3643): VFY: unable to resolve static method 315: Landroid/hardware/Camera;.getNumberOfCameras ()I
02-06 12:29:14.532: I/ActivityThread(3643): queueIdle
02-06 12:29:14.532: W/ActivityNative(3643): send ACTIVITY_IDLE_TRANSACTION
02-06 12:29:19.402: W/dalvikvm(3643): VFY: unable to resolve static method 318: Landroid/hardware/Camera;.open (I)Landroid/hardware/Camera;
02-06 12:29:20.872: I/ActivityThread(3643): queueIdle
02-06 12:29:20.872: W/ActivityNative(3643): send ACTIVITY_IDLE_TRANSACTION
02-06 12:29:25.872: I/ActivityThread(3643): queueIdle
02-06 12:29:25.872: W/ActivityNative(3643): send ACTIVITY_IDLE_TRANSACTION
02-06 12:29:44.262: I/ActivityThread(3643): queueIdle
02-06 12:29:44.262: W/ActivityNative(3643): send ACTIVITY_IDLE_TRANSACTION
02-06 12:29:47.102: I/ActivityThread(3643): queueIdle
02-06 12:29:47.102: W/ActivityNative(3643): send ACTIVITY_IDLE_TRANSACTION
02-06 12:29:58.302: I/ActivityThread(3643): queueIdle
02-06 12:29:58.312: W/ActivityNative(3643): send ACTIVITY_IDLE_TRANSACTION
[/ul]

The following is my code for CrimeCameraFragment.java


package com.spoors.criminalintent1;

import java.io.FileOutputStream;
import java.io.IOException;


import java.util.List;
import java.util.UUID;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.hardware.Camera;
import android.hardware.Camera.Size;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

public class CrimeCameraFragment extends Fragment {
    private static final String TAG = "CrimeCameraFragment";

    public static final String EXTRA_PHOTO_FILENAME = "CrimeCameraFragment.filename";

    private Camera mCamera;
    private SurfaceView mSurfaceView;
    private View mProgressContainer;

    private Camera.ShutterCallback mShutterCallback = new Camera.ShutterCallback() {
        public void onShutter() {
            // display the progress indicator
            mProgressContainer.setVisibility(View.VISIBLE);
        }
    };
    private Camera.PictureCallback mJpegCallBack = new Camera.PictureCallback() {
        public void onPictureTaken(byte[] data, Camera camera) {
            // create a filename
            String filename = UUID.randomUUID().toString() + ".jpg";
            // save the jpeg data to disk
            FileOutputStream os = null;
            boolean success = true;
            try {
                os = getActivity().openFileOutput(filename, Context.MODE_PRIVATE);
                os.write(data);
            } catch (Exception e) {
                Log.e(TAG, "Error writing to file " + filename, e);
                success = false;
            } finally {
                try {
                    if (os != null)
                        os.close();
                } catch (Exception e) {
                    Log.e(TAG, "Error closing file " + filename, e);
                    success = false;
                } 
            }
            
            if (success) {
                // set the photo filename on the result intent
                if (success) {
                    Intent i = new Intent();
                    i.putExtra(EXTRA_PHOTO_FILENAME, filename);
                    getActivity().setResult(Activity.RESULT_OK, i);
                } else {
                    getActivity().setResult(Activity.RESULT_CANCELED);
                }
            }
            getActivity().finish();
        }
    };

    @Override
    @SuppressWarnings("deprecation")
    public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.fragment_crime_camera, parent, false);

        mProgressContainer = v.findViewById(R.id.crime_camera_progressContainer);
        mProgressContainer.setVisibility(View.INVISIBLE);
        Button takePictureButton = (Button)v.findViewById(R.id.crime_camera_takePictureButton);
        takePictureButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                if (mCamera != null) {
            	    mCamera.takePicture(mShutterCallback, null, mJpegCallBack);
            	}
            } 
        });

        mSurfaceView = (SurfaceView)v.findViewById(R.id.crime_camera_surfaceView);
        SurfaceHolder holder = mSurfaceView.getHolder();
        // deprecated, but required for pre-3.0 devices
        holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
        holder.addCallback(new SurfaceHolder.Callback() {

            public void surfaceCreated(SurfaceHolder holder) {
                // tell the camera to use this surface as its preview area
                try {
                    if (mCamera != null) {
                        mCamera.setPreviewDisplay(holder);
                    }
                } catch (IOException exception) {
                    Log.e(TAG, "Error setting up preview display", exception);
                }
            }

            public void surfaceDestroyed(SurfaceHolder holder) {
                // we can no longer display on this surface, so stop the preview.
                if (mCamera != null) {
                    mCamera.stopPreview();
                }
            }

            public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
            	if (mCamera == null) return;
            	
                // the surface has changed size; update the camera preview size
                Camera.Parameters parameters = mCamera.getParameters();
                Size s = getBestSupportedSize(parameters.getSupportedPreviewSizes(), w, h);
                parameters.setPreviewSize(s.width, s.height);
                s = getBestSupportedSize(parameters.getSupportedPictureSizes(), w, h);
                parameters.setPictureSize(s.width, s.height);
                mCamera.setParameters(parameters);
                try {
                    mCamera.startPreview();
                } catch (Exception e) {
                    Log.e(TAG, "Could not start preview", e);
                    mCamera.release();
                    mCamera = null;
                }
            }
        });
        
        return v; 
    }

    @TargetApi(9)
    @Override
    public void onResume() {
        super.onResume();
        
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {    
            mCamera = Camera.open(0);
        } else {
            mCamera = Camera.open();
        }
    }

    @Override
    public void onPause() {
        super.onPause();

        if (mCamera != null) {
            mCamera.release();
            mCamera = null;
        }
    }

    /** a simple algorithm to get the largest size available. For a more 
     * robust version, see CameraPreview.java in the ApiDemos 
     * sample app from Android. */
    private Size getBestSupportedSize(List<Size> sizes, int width, int height) {
        Size bestSize = sizes.get(0);
        int largestArea = bestSize.width * bestSize.height;
        for (Size s : sizes) {
            int area = s.width * s.height;
            if (area > largestArea) {
                bestSize = s;
                largestArea = area;
            }
        }
        return bestSize;
    }
    
}




and this is my xml file

[code]
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        android:id="@+id/crime_camera_preview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal" >

        <SurfaceView
            android:id="@+id/crime_camera_surfaceView"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1" />

        <Button
            android:id="@+id/crime_camera_takePictureButton"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:text="@string/take" />
    </LinearLayout>

    <FrameLayout
        android:id="@+id/crime_camera_progressContainer"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clickable="true" >

        <ProgressBar
            style="@android:style/Widget.ProgressBar.Large"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center" />
    </FrameLayout>

</FrameLayout>



Can anyone say what the problem is..???
[/code]