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) 展开
2014-04-24
展开全部
把logcat里面的错误信息贴出来呗。
更多追问追答
追问
log太多贴不下!!要不你把QQ给我吧!大神,求带啊!
追答
错误信息的Log怎么可能会很多呢,把Exception贴出来就好了。
微测检测5.10
2023-05-10 广告
2023-05-10 广告
您好!建议咨 深圳市微测检测有限公司,已建立起十余个专业实验室,企业通过微测检测就可以获得一站式的测试与认 证解决方案;(EMC、RF、MFi、BQB、QI、USB、安全、锂电池、快充、汽车电子EMC、汽车手机互 联、语音通话质量),认证遇...
点击进入详情页
本回答由微测检测5.10提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |