android 开发 调用系统相机拍照并显示。为什么在点击确定时候会显示程序意外终止?
代码如下:publicclassActivity01extendsActionBarActivity{privateImageViewimageView;protecte...
代码如下:
public class Activity01 extends ActionBarActivity{
private ImageView imageView;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.fragment_main);
}
public void onclick(View v)
{
switch (v.getId()) {
case R.id.btn_camera:
{
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent,Activity01.DEFAULT_KEYS_DIALER);
}
break;
default:
break;
}
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(resultCode==RESULT_OK)
{
if(data!=null)
{
Bundle extras = data.getExtras();
Bitmap bmp = (Bitmap) extras.get("data");
imageView.setImageBitmap(bmp); //设置照片现实在界面上
}else{
Toast.makeText(Activity01.this, "获取资源失败", Toast.LENGTH_LONG).show();
return;
}
}
}
}
04-25 01:33:39.787: E/CameraHolder(717): at android.hardware.Camera.<init>(Camera.java:258)
04-25 01:33:39.787: E/CameraHolder(717): at android.hardware.Camera.open(Camera.java:220)
04-25 01:33:39.787: E/CameraHolder(717): at com.android.camera.CameraHolder.open(CameraHolder.java:124)
04-25 01:33:39.787: E/CameraHolder(717): at com.android.camera.Camera.ensureCameraDevice(Camera.java:1608)
04-25 01:33:39.787: E/CameraHolder(717): at com.android.camera.Camera.startPreview(Camera.java:1660) 展开
public class Activity01 extends ActionBarActivity{
private ImageView imageView;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.fragment_main);
}
public void onclick(View v)
{
switch (v.getId()) {
case R.id.btn_camera:
{
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent,Activity01.DEFAULT_KEYS_DIALER);
}
break;
default:
break;
}
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(resultCode==RESULT_OK)
{
if(data!=null)
{
Bundle extras = data.getExtras();
Bitmap bmp = (Bitmap) extras.get("data");
imageView.setImageBitmap(bmp); //设置照片现实在界面上
}else{
Toast.makeText(Activity01.this, "获取资源失败", Toast.LENGTH_LONG).show();
return;
}
}
}
}
04-25 01:33:39.787: E/CameraHolder(717): at android.hardware.Camera.<init>(Camera.java:258)
04-25 01:33:39.787: E/CameraHolder(717): at android.hardware.Camera.open(Camera.java:220)
04-25 01:33:39.787: E/CameraHolder(717): at com.android.camera.CameraHolder.open(CameraHolder.java:124)
04-25 01:33:39.787: E/CameraHolder(717): at com.android.camera.Camera.ensureCameraDevice(Camera.java:1608)
04-25 01:33:39.787: E/CameraHolder(717): at com.android.camera.Camera.startPreview(Camera.java:1660) 展开
1个回答
2014-04-24
展开全部
把logcat里面的错误信息贴出来呗。
更多追问追答
追问
log太多贴不下!!要不你把QQ给我吧!大神,求带啊!
追答
错误信息的Log怎么可能会很多呢,把Exception贴出来就好了。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询