java.Lang.RuntimeException,setParameters在android(4.1.1)版本中失败

java.Lang.RuntimeException,setParameters在android(4.1.1)版本中失败,android,android-camera,android-sdcard,android-camera-intent,Android,Android Camera,Android Sdcard,Android Camera Intent,我开发了一个应用程序,它可以在打卡时捕捉照片。它在Acer标签上运行良好(拍摄图像并保存在SD卡中)。现在,当我在三星Galaxy(Android-4.1.1)上运行相同的应用程序时,当单击“打卡”时,我的应用程序会“不幸地停止”。我的代码是这样的 // ClockIn functionality clockin_btn.setOnClickListener(new View.OnClickListener() { public void onClick(View v) {

我开发了一个应用程序,它可以在打卡时捕捉照片。它在Acer标签上运行良好(拍摄图像并保存在SD卡中)。现在,当我在三星Galaxy(Android-4.1.1)上运行相同的应用程序时,当单击“打卡”时,我的应用程序会“不幸地停止”。我的代码是这样的

// ClockIn functionality
clockin_btn.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {       
        clockin_btn.setEnabled(false);
        camera.stopPreview();
        capturePhoto(0);
      // showing one error here in log cat
        previewing = false;         
        clockin_label.setText(String.format(session_msg,logout_seconds));   
        ticker.setBase(SystemClock.elapsedRealtime()); 
        ticker.start();
    }       
});

private String capturePhoto(int clockInOutMode) {

    final int mode = clockInOutMode;
    img_file = String.format("%d.jpg", System.currentTimeMillis());

    Camera.PictureCallback mCall = new Camera.PictureCallback() {               

        public void onPictureTaken(byte[] data, Camera camera) {

            try {    

                Bitmap mBitmap = BitmapFactory.decodeByteArray(data, 0, data.length);           
                File file = new File(Constants.EMP_IMG_LOCATION, img_file);           
                FileOutputStream fOut = new FileOutputStream(file);                    
                mBitmap.compress(Bitmap.CompressFormat.JPEG, 80, fOut);               
                fOut.flush();               
                fOut.close();

                if ( mode == 0) {
                    clockIn(img_file);
                } else {
                    clockOut(img_file);
                }

            } catch (FileNotFoundException e) {
                e.printStackTrace();

            } catch (IOException e) {        
                e.printStackTrace();

            } 
        }   

    };  

    Camera.Parameters cameraParams = camera.getParameters();
    List<Camera.Size> sizes = cameraParams.getSupportedPictureSizes();
    Camera.Size result = null;
    for (int i=0;i<sizes.size();i++){
        result = (Size) sizes.get(i);
        Log.i("PictureSize", "Supported Size.Width: " + result.width + "height: " +result.height);         
    }

    cameraParams.setPictureSize(640, 480);
    camera.setParameters(cameraParams);
            System.gc();
    camera.setPreviewCallback(null);
    camera.takePicture(null, null, mCall);

       // showing one error here in logcat

    return img_file;
}
和我的android.manifest.xml文件:

     <uses-feature android:name="android.hardware.camera" />
 <uses-feature android:name="android.hardware.camera.autofocus" />
 <used-feature android:name="android.hardware.location" />
 <used-feature android:name="android.hardware.camera.setParameters" />


它并非在所有情况下都有效。调用
getSupportedPictureSizes()
就可以得到列表。并从列表中选择
setPictureSize()
中的参数。

在调用takePicture方法之前调用startPreview方法
camera.takePicture(null,null,mCall)
private void startPreview() {
        if (cameraConfigured && camera!=null) {
          camera.startPreview();
          inPreview=true;
        }
      }

通过这个我解决了我的问题。。。这可能会对你们有所帮助。

i你们评论设置参数,然后应用程序是否工作?@ρ∑ρєK不,它不工作。现在错误显示在下一行,即camera.takePicture(null,null,mCall)@拉贾帕拉,我也面临同样的问题。你能根据我的代码帮我解决这个问题吗..System.gc();-请不要那样做!这是一个n00b的尝试,它解决不了任何问题。它只提示JVM现在是进行GC的好时机,但最终是JVM决定是否进行GC。
private void flipBackToFrontCamera() {

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

    mCamera = Camera.open(1);

    if (mCamera != null) {
        try {
            mCamera.setPreviewDisplay(surfaceView.getHolder());
            mCamera.startPreview();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
private void flipBackToFrontCamera() {

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

    mCamera = Camera.open(1);

    if (mCamera != null) {
        try {
            mCamera.setPreviewDisplay(surfaceView.getHolder());
            mCamera.startPreview();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}