Click here to Skip to main content
15,943,406 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I Can't get images from the gallery, Can help me with anyone..?
Please see logcat output ...

What I have tried:

Java
<pre>@Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode==0&& resultCode==RESULT_OK)
        {

                Uri uri = data.getData();
            String [] filePathColumn = {MediaStore.Images.Media.DATA};
            Cursor cursor = getContentResolver().query(uri,filePathColumn,null,null,null);
            cursor.moveToFirst();

            int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
            String picturePath = cursor.getString(columnIndex);
            cursor.close();
            ByteArrayOutputStream bao = new ByteArrayOutputStream();
            bitmap = BitmapFactory.decodeFile(picturePath);

            imageArray = bao.toByteArray();
            bitmap.compress(Bitmap.CompressFormat.JPEG,100,bao);
            imageView.setImageBitmap(bitmap);
        }else {
            Toast.makeText(this, "Something wrong !", Toast.LENGTH_SHORT).show();
        }
    }




Here is logcat output...
Java
E/BitmapFactory: Unable to decode stream: java.io.FileNotFoundException: _data (No such file or directory)
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.noteapplication, PID: 7085
    java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=0, result=-1, data=Intent { dat=content://com.android.providers.media.documents/document/image:62 flg=0x1 }} to activity {com.example.noteapplication/com.example.input_show.InputActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.graphics.Bitmap.compress(android.graphics.Bitmap$CompressFormat, int, java.io.OutputStream)' on a null object reference
        at android.app.ActivityThread.deliverResults(ActivityThread.java:4053)
        at android.app.ActivityThread.handleSendResult(ActivityThread.java:4096)
        at android.app.ActivityThread.-wrap20(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1516)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6077)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
     Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.graphics.Bitmap.compress(android.graphics.Bitmap$CompressFormat, int, java.io.OutputStream)' on a null object reference
        at com.example.input_show.InputActivity.onActivityResult(InputActivity.java:107)
Posted
Updated 19-Nov-21 21:18pm
Comments
David Crow 22-Nov-21 9:37am    
The NullPointerException is pretty straightforward. You are calling the compress() method on a null object, in this case bitmap. See why BitmapFactory.decodeFile() is returning null.

1 solution

Read the error message(s):
Quote:
E/BitmapFactory: Unable to decode stream: java.io.FileNotFoundException: _data (No such file or directory)


You are trying to read an image from a file but it or the path that contains it does not exist.

We can't do anything about that - you need to use the debugger to identify the path, and then work out why it isn't correct.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900