java.lang.RuntimeException的,setParameters失败的Android(4.1.1)版 [英] java.Lang.RuntimeException, setParameters failed in android(4.1.1) version
问题描述
我已经开发了拍摄照片的应用程序时拳打在的时候。它的工作好宏碁标签(捕捉的图像并保存在SD卡)。现在,当我运行在三星Galaxy(Android的4.1.1)相同的应用我的应用程序是越来越不幸的是应用程序已经停止时,点击打孔in。和我的code是这里去..
// ClockIn功能
clockin_btn.setOnClickListener(新View.OnClickListener(){
公共无效的onClick(视图v){
clockin_btn.setEnabled(假);
camera.stop preVIEW();
capturePhoto(0);
//显示有一个错误在这里记录的猫
previewing = FALSE;
clockin_label.setText(的String.Format(session_msg,logout_seconds));
ticker.setBase(SystemClock.elapsedRealtime());
ticker.start();
}
});
私人字符串capturePhoto(INT clockInOutMode){
最终诠释模式= clockInOutMode;
img_file =的String.Format(%D.JPG,System.currentTimeMillis的());
Camera.PictureCallback MCALL =新Camera.PictureCallback(){
公共无效onPictureTaken(byte []的数据,摄像头摄像头){
尝试 {
位图mBitmap = BitmapFactory.de codeByteArray(数据,0,data.length);
档案文件=新的文件(Constants.EMP_IMG_LOCATION,img_file);
FileOutputStream中FOUT =新的FileOutputStream(文件);
mBitmap.com preSS(Bitmap.Com pressFormat.JPEG,80,FOUT);
fOut.flush();
fOut.close();
如果(模式== 0){
clockIn(img_file);
} 其他 {
CLOCKOUT(img_file);
}
}赶上(FileNotFoundException异常E){
e.printStackTrace();
}赶上(IOException异常E){
e.printStackTrace();
}
}
};
Camera.Parameters cameraParams = camera.getParameters();
名单< Camera.Size>尺寸= cameraParams.getSupportedPictureSizes();
Camera.Size结果= NULL;
的for(int i = 0; I< sizes.size();我++){
结果=(尺寸)sizes.get(我);
Log.i(PictureSize,支持Size.Width:+ result.width +的高度:+ result.height);
}
cameraParams.setPictureSize(640,480);
camera.setParameters(cameraParams);
System.gc()的;
camera.set previewCallback(空);
camera.takePicture(NULL,NULL,MCALL);
//显示有一个错误在这里的logcat
返回img_file;
}
我的logcat是显示为:
4月3日至27号:52:19.273:E / AndroidRuntime(4105):致命异常:主要
四月3号至27号:52:19.273:E / AndroidRuntime(4105):java.lang.RuntimeException的:setParameters失败
四月3号至27号:52:19.273:E / AndroidRuntime(4105):在android.hardware.Camera.native_setParameters(本机方法)
四月3号至27号:52:19.273:E / AndroidRuntime(4105):在android.hardware.Camera.setParameters(Camera.java:1452)
和我android.manifest.xml文件:
<使用特征的android:NAME =android.hardware.camera/>
<使用特征的android:NAME =android.hardware.camera.autofocus/>
<二手功能的Android:名称=android.hardware.location/>
<二手功能的Android:名称=android.hardware.camera.setParameters/>
调用start preVIEW方法调用takePicture方法 camera.takePicture(NULL,NULL,MCALL)之前;
我用一开始preVIEW方法
私人无效开始preVIEW(){
如果(cameraConfigured&安培;&安培;!摄像头= NULL){
camera.start preVIEW();
在preVIEW = TRUE;
}
}
和通过这个我解决了我的问题......它可以帮助你们。
I have developed an application which captures a photo when punch in at the time. It's working good on Acer tab(capturing image and saves in sdcard). Now when I run the same application in Samsung Galaxy(Android-4.1.1) My app is getting 'Unfortunately app has stopped' when click on punch in. and my code is here goes..
// 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;
}
My Logcat is showing as:
03-27 04:52:19.273: E/AndroidRuntime(4105): FATAL EXCEPTION: main
03-27 04:52:19.273: E/AndroidRuntime(4105): java.lang.RuntimeException: setParameters failed
03-27 04:52:19.273: E/AndroidRuntime(4105): at android.hardware.Camera.native_setParameters(Native Method)
03-27 04:52:19.273: E/AndroidRuntime(4105): at android.hardware.Camera.setParameters(Camera.java:1452)
and my android.manifest.xml file:
<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" />
Call the startPreview method before you call takePicture method camera.takePicture(null, null, mCall);
and the startPreview method I used is
private void startPreview() {
if (cameraConfigured && camera!=null) {
camera.startPreview();
inPreview=true;
}
}
and through this I solved my issue... It may help you guys.
这篇关于java.lang.RuntimeException的,setParameters失败的Android(4.1.1)版的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!