发送位图图像路径但具有null错误

时间:2015-03-27 18:39:40

标签: android android-intent bitmap

我发送用户从厨房中选择的图像路径并将其发送到视图类我认为它获取路径但是当我想在图像视图中设置位图时应用程序崩溃。我不知道为什么会发生这种情况 : 这是我的发送代码:

public  void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {
            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]);
            String picturePath = cursor.getString(columnIndex);
            cursor.close();
            CanvasView c =new CanvasView(this);
            c.setCanvasPath(picturePath); //this send
        }

和另一只手在我的View类中:

public class CanvasView extends View {
    Bitmap canvasBitmap;
    Canvas drawCanvas;
    public CanvasView(Context context) {
        super(context);
    }
    public void setCanvasPath(String bitmap_path) {
        Log.e("logiiiiiiiiin",bitmap_path);
        BitmapFactory.Options decode_options = new BitmapFactory.Options();
        decode_options.inMutable = true;
        canvasBitmap  = BitmapFactory.decodeFile(bitmap_path,decode_options);
        ImageView imageView = (ImageView) findViewById(R.id.imgView);
        imageView.setImageBitmap(canvasBitmap);
    }

    @Override

    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

    }
}

这是我的日志:

03-27 22:57:24.573    8941-8941/com.example.pooyafayyaz.first_photo_edit_test E/Trace﹕ error opening trace file: No such file or directory (2)
03-27 22:57:46.123    8941-8941/com.example.pooyafayyaz.first_photo_edit_test E/logiiiiiiiiin﹕ /storage/sdcard0/viber/media/Viber Images/image-d89aac5f0af482a6fe466f1cd32f9836d51cd6d30326b25a377a8b213cab72b8-V.jpg
03-27 22:57:46.253    8941-8941/com.example.pooyafayyaz.first_photo_edit_test E/AndroidRuntime﹕ FATAL EXCEPTION: main
    java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { act=com.htc.HTCAlbum.action.ITEM_PICKER_FROM_COLLECTIONS dat=content: typ=image/jpeg (has extras) }} to activity {com.example.pooyafayyaz.first_photo_edit_test/com.example.pooyafayyaz.first_photo_edit_test.second}: java.lang.NullPointerException
            at android.app.ActivityThread.deliverResults(ActivityThread.java:3660)
            at android.app.ActivityThread.handleSendResult(ActivityThread.java:3710)
            at android.app.ActivityThread.access$1100(ActivityThread.java:151)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1378)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:155)
            at android.app.ActivityThread.main(ActivityThread.java:5536)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1074)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:841)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.NullPointerException
            at com.example.pooyafayyaz.first_photo_edit_test.CanvasView.setCanvasPath(CanvasView.java:28)
            at com.example.pooyafayyaz.first_photo_edit_test.second.onActivityResult(second.java:70)
            at android.app.Activity.dispatchActivityResult(Activity.java:5275)
            at android.app.ActivityThread.deliverResults(ActivityThread.java:3656)
            at android.app.ActivityThread.handleSendResult(ActivityThread.java:3710)
            at android.app.ActivityThread.access$1100(ActivityThread.java:151)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1378)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:155)
            at android.app.ActivityThread.main(ActivityThread.java:5536)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1074)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:841)
            at dalvik.system.NativeStart.main(Native Method)
03-27 22:59:49.043  10261-10261/com.example.pooyafayyaz.first_photo_edit_test E/Trace﹕ error opening trace file: No such file or directory (2)
03-27 23:00:05.423  10261-10261/com.example.pooyafayyaz.first_photo_edit_test E/logiiiiiiiiin﹕ /storage/sdcard0/viber/media/Viber Images/image-d89aac5f0af482a6fe466f1cd32f9836d51cd6d30326b25a377a8b213cab72b8-V.jpg
03-27 23:00:56.163  11670-11670/com.example.pooyafayyaz.first_photo_edit_test E/Trace﹕ error opening trace file: No such file or directory (2)
03-27 23:01:06.133  11670-11670/com.example.pooyafayyaz.first_photo_edit_test E/logiiiiiiiiin﹕ /storage/sdcard0/viber/media/Viber Images/image-d89aac5f0af482a6fe466f1cd32f9836d51cd6d30326b25a377a8b213cab72b8-V.jpg

1 个答案:

答案 0 :(得分:0)

我无法确定,但究竟哪一行是空指针发生的?是imageView吗?如果是这样,你的观点可能还没有被夸大。