无法在android中解码流java.io.FileNotFoundException?

无法在android中解码流java.io.FileNotFoundException?,java,android,filenotfoundexception,bitmapfactory,Java,Android,Filenotfoundexception,Bitmapfactory,我是android新手,当我尝试使用decodefile()时,我遇到了这个错误 这是密码 protected void onActivityResult(int requestCode, int resultCode, Intent data) { if ((requestCode == PICK_FROM_GALLERY ) && (resultCode == RESULT_OK) && (data != null)){ se

我是android新手,当我尝试使用
decodefile()
时,我遇到了这个错误

这是密码

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

 if ((requestCode == PICK_FROM_GALLERY ) && (resultCode == RESULT_OK) &&       (data != null)){
         selectedImageUri = data.getData( );
         Log.e("Path1", ""+selectedImageUri);
         path1 = selectedImageUri.getPath();
         file = new File(path1);
         path =file.getAbsolutePath();
         Log.e("Path2", file.getAbsolutePath());

         mImageView.setImageURI(selectedImageUri);
    }}

protected void badButtonPressed() {
    final long startTime = SystemClock.uptimeMillis();


    BitmapFactory.Options options = new BitmapFactory.Options();
    // Part 1: Decode image
   >> Bitmap unscaledBitmap = BitmapFactory.decodeFile(path, options);
     imageHeight = options.outHeight;
     imageWidth = options.outWidth;
    Log.e("w", ""+imageWidth);
    Log.e("h", ""+imageHeight);
请告诉我我的错误。

请试一试

int PICK_FROM_GALLERY = 3;
String path;
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    if (requestCode == PICK_FROM_GALLERY 
            && resultCode == Activity.RESULT_OK) {

        try {
            Uri selectedImage = data.getData();
            String[] filePathColumn = { MediaStore.Images.Media.DATA };

            Cursor cursor = getContentResolver().query(selectedImage,
                    filePathColumn, null, null, null);
            cursor.moveToFirst();

            int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
            path = cursor.getString(columnIndex);



            cursor.close();
        } catch (NullPointerException e) {

        }

    }
}

public void pickFromGallery()
{
    Intent i = new Intent(Intent.ACTION_PICK,
             android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    startActivityForResult(i, PICK_FROM_GALLERY);
}
找到了这个答案

Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                    intent.setType("image/*");
                    startActivityForResult(intent, SELECT_IMAGE);

    protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
        super.onActivityResult(requestCode, resultCode, intent);
        if (resultCode == RESULT_OK) {
            if (requestCode == SELECT_IMAGE) {
                try {
                    selectedImagePath = getAbsolutePath(intent.getData());
                    mImageCaptureUri = intent.getData();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }

    }

    public String getAbsolutePath(Uri uri) {
        String[] projection = {MediaStore.MediaColumns.DATA};
        @SuppressWarnings("deprecation")
        Cursor cursor = managedQuery(uri, projection, null, null, null);
        if (cursor != null) {
            int column_index =    cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA);
            cursor.moveToFirst();
            return cursor.getString(column_index);
        } else
            return null;
    }

请发布完整的stacktrace。欢迎使用Stack Overflow。我已经编辑了你的文章来解决一些英语问题。我还用两个星号将函数名加粗。我看不出你提到的错误。请编辑您的帖子并向我们显示错误(使用行开头的>进行标记)。@RohutGupta您已将函数名加粗,为什么?当代码格式已经存在时?您使用的是哪个android版本?仍然为空指针错误当您调用badButtonPressed()时,“路径”中没有任何内容?我可以显示gallery中的图像,但当我当时尝试对该图像执行缩放时,会出现此错误,请写入清单。BitmapFactory(1682):无法解码流:java.lang.NullPointerException。。。。。。。。。。。。。。。。。。。当我调用badButtonPressed()时