在nexus中使用安卓相机捕获图像后的空指针5

在我的应用程序中,我使用android设备相机捕捉我的图像。 在某些设备上它可以正常工作,但不是全部,我只是测试它LG的LG nexus 5 E960,在我捕捉到图像后,它总是会崩溃而无法保存结果,这是我的代码:

  Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
  startActivityForResult(cameraIntent, 1);



  protected void onActivityResult(int requestCode, int resultCode,
        Intent returnimage) {
    super.onActivityResult(requestCode, resultCode, returnimage);

    switch (requestCode) {
    case 1:
        if (resultCode == RESULT_OK) {

            Uri selectedImage = returnimage.getData();

            String stringUri;
            stringUri = selectedImage.toString();
            Intent i1 = new Intent(MainActivity.this, Secondpage.class);
             i1.putExtra("Stringuri",stringUri );
            startActivity(i1);


        }
        break;

我的logcat是:

     java.lang.RuntimeException: Failure delivering result ResultInfo{who=null,
     request=1, result=-1, data=Intent { act=inline-data (has extras) }} to activity 
     {com.photostikers/com.photostikers.MainActivity}: java.lang.NullPointerException
     02-13 12:27:54.315: E/AndroidRuntime(28759):  at 
     android.app.ActivityThread.deliverResults(ActivityThread.java:3365)
     02-13 12:27:54.315: E/AndroidRuntime(28759):  at  
     android.app.ActivityThread.performResumeActivity(ActivityThread.java:2775)
     02-13 12:27:54.315: E/AndroidRuntime(28759):  ... 12 more
     02-13 12:27:54.315: E/AndroidRuntime(28759): Caused by: java.lang.NullPointerException
     02-13 12:27:54.315: E/AndroidRuntime(28759):  at 
     com.photostikers.MainActivity.onActivityResult(MainActivity.java:335)
     02-13 12:27:54.315: E/AndroidRuntime(28759):  at 
     android.app.Activity.dispatchActivityResult(Activity.java:5423)
     02-13 12:27:54.315: E/AndroidRuntime(28759):  at 
     android.app.ActivityThread.deliverResults(ActivityThread.java:3361)
     02-13 12:27:54.315: E/AndroidRuntime(28759):  ... 13 more

使用像

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
        Bundle extras = data.getExtras();
        Bitmap imageBitmap = (Bitmap) extras.get("data");
        Intent i1 = new Intent(MainActivity.this, Secondpage.class);
        i1.putExtra("bitmap",imageBitmap );
        startActivity(i1);
    }
}

并在Secondpage Activity

获得像这样的图像

Bitmap bitImage = getIntent().getParcelableExtra("bitmap");
your_image+_view.setImageBitmap(bitImage);

通过Android开发人员文档获取缩略图


它在nexus5中成为共同的问题。

取而代之的是:

Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, 1);

尝试这个:

Uri mPhotoUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, 
        new ContentValues());
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, mPhotoUri);
startActivityForResult(intent,CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE_CONTENT_RESOLVER);

看看这个:http://cssmay.com/question/tag/tag-camera,我认为它可以帮助你很多。

链接地址: http://www.djcxy.com/p/77293.html

上一篇: Null pointer after capturing image using android camera in nexus 5

下一篇: Google Protobuf empty fields and messages criteria (Python)