0

OnActivityResultメソッドのデータに対して常にnull値を取得しています。余分なものなしでインテントを使用してみましたが、それもうまくいきませんでした。

package com.mypack;

import java.io.ByteArrayOutputStream;

import android.app.Activity;
import android.content.ContentValues;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.widget.Button;

public class PhotoUploadRecommenderActivity extends Activity {

    private Button accettoButton;
    private static final int CAM_REQUEST = 1337;
    private Uri mCapturedImageURI;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.photo_upload_recommendation);

        setUpView();

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {

        super.onActivityResult(requestCode, resultCode, data);

          if (requestCode == CAM_REQUEST && resultCode == RESULT_OK) {
             // Bitmap thumbnail = (Bitmap) data.getExtras().get("data");
              //imgTakenPhoto.setImageBitmap(thumbnail);

              String[] projection = { MediaStore.Images.Media.DATA}; 
              Cursor cursor = managedQuery(mCapturedImageURI, projection, null, null, null); 
              int column_index_data = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); 
              cursor.moveToFirst(); 
              String capturedImageFilePath = cursor.getString(column_index_data);

               // your bitmap
              ByteArrayOutputStream bs = new ByteArrayOutputStream();
              //thumbnail.compress(Bitmap.CompressFormat.PNG, 0, bs);


              Intent intent = new Intent(getApplicationContext(),PhotoPreviewActivity.class);
              intent.putExtra("byteArray", capturedImageFilePath);

              startActivity(intent);
          }
    }


    private void setUpView() {


        accettoButton = (Button)findViewById(R.id.accetto_button);
        accettoButton.setOnClickListener(new btnTakePhotoClicker());

    }

    class btnTakePhotoClicker implements Button.OnClickListener
    {


        public void onClick(View v) {

            String fileName = "temp.jpg";  
            ContentValues values = new ContentValues();  
            values.put(MediaStore.Images.Media.TITLE, fileName);  
            mCapturedImageURI = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);  

            Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
            cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, mCapturedImageURI);  
            startActivityForResult(cameraIntent,CAM_REQUEST);
        }
    }

}

カメラインテントを使用して画像をキャプチャしたい。このエラーが発生します。これには、カーソルのnullポインタ例外も含まれます。

java.lang.RuntimeException: Unable to resume activity {com.mypack/com.mypack.PhotoUploadRecommenderActivity}: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1337, result=-1, data=null} to activity {com.mypack/com.mypack.PhotoUploadRecommenderActivity}: java.lang.NullPointerException
4

1 に答える 1

0
intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
mImageCaptureUri = Uri.fromFile(new File(Environment.getExternalStorageDirectory(),
                   "tmp_avatar.jpg"));
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, mImageCaptureUri);
startActivityForResult(intent, 1);

OnActivityResult:

Bundle extras = data.getExtras();
if (extras != null) {               
usrPic = extras.getParcelable("data");
    if(usrPic != null){
        imageView.setImageBitmap(usrPic);
}
于 2012-12-03T13:15:48.077 に答える