Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

SOLVED: Android 4.0 crush after loading image in imageView

Peyu:

I'm new at Android Studio and I'm trying to make a simple app. All I want it's to pick an image from Gallery and show it in an imageView. this is what I got until now:

Activity:


package com.example.peyu.bellatrix_01b;

import android.content.Intent;
import android.net.Uri;
import android.provider.MediaStore;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

public class ImageActivity extends AppCompatActivity {

public final static String TAG_LOG = ImageActivity.class.getSimpleName();
public static final int PICK_IMAGE = 100;
public Uri imageURI;
public ImageView imgPicture;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_image);

Button btnAbrirImagen = (Button) findViewById(R.id.btnAbrirImagen);
ImageView imgPicture = (ImageView) findViewById(R.id.imgPicture);

}

public void AbrirImagen(View v) {

Intent photoPickerIntent= new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.INTERNAL_CONTENT_URI);
startActivityForResult(photoPickerIntent, PICK_IMAGE);

}

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


if(resultCode == RESULT_OK && requestCode == PICK_IMAGE){

imageURI = data.getData();
imgPicture.setImageURI(imageURI);

}


}
}

I Understand that the resultcode is getting a -1, but I don't know why... any idea?? thank you

This is the catlog:

09-01 22:34:50.145 20063-20063/com.example.peyu.bellatrix_01b W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x41a53c98) 09-01 22:34:50.145 20063-20063/com.example.peyu.bellatrix_01b W/dalvikvm: threadid=1: uncaught exception occurred 09-01 22:34:50.146 20063-20063/com.example.peyu.bellatrix_01b W/System.err: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=100, result=-1, data=Intent { dat=content://media/external/images/media/89391 flg=0x1 }} to activity {com.example.peyu.bellatrix_01b/com.example.peyu.bellatrix_01b.ImageActivity}: java.lang.NullPointerException 09-01 22:34:50.146 20063-20063/com.example.peyu.bellatrix_01b W/System.err: at android.app.ActivityThread.deliverResults(ActivityThread.java:3592) 09-01 22:34:50.146 20063-20063/com.example.peyu.bellatrix_01b W/System.err: at android.app.ActivityThread.handleSendResult(ActivityThread.java:3635) 09-01 22:34:50.146 20063-20063/com.example.peyu.bellatrix_01b W/System.err: at android.app.ActivityThread.access$1300(ActivityThread.java:151) 09-01 22:34:50.146 20063-20063/com.example.peyu.bellatrix_01b W/System.err: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1390) 09-01 22:34:50.146 20063-20063/com.example.peyu.bellatrix_01b W/System.err: at android.os.Handler.dispatchMessage(Handler.java:110) 09-01 22:34:50.146 20063-20063/com.example.peyu.bellatrix_01b W/System.err: at android.os.Looper.loop(Looper.java:193) 09-01 22:34:50.147 20063-20063/com.example.peyu.bellatrix_01b W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5333) 09-01 22:34:50.147 20063-20063/com.example.peyu.bellatrix_01b W/System.err: at java.lang.reflect.Method.invokeNative(Native Method) 09-01 22:34:50.147 20063-20063/com.example.peyu.bellatrix_01b W/System.err: at java.lang.reflect.Method.invoke(Method.java:515) 09-01 22:34:50.147 20063-20063/com.example.peyu.bellatrix_01b W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824) 09-01 22:34:50.147 20063-20063/com.example.peyu.bellatrix_01b W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640) 09-01 22:34:50.147 20063-20063/com.example.peyu.bellatrix_01b W/System.err: at dalvik.system.NativeStart.main(Native Method) 09-01 22:34:50.147 20063-20063/com.example.peyu.bellatrix_01b W/System.err: Caused by: java.lang.NullPointerException 09-01 22:34:50.150 20063-20063/com.example.peyu.bellatrix_01b W/System.err: at com.example.peyu.bellatrix_01b.ImageActivity.onActivityResult(ImageActivity.java:70) 09-01 22:34:50.151 20063-20063/com.example.peyu.bellatrix_01b W/System.err: at android.app.Activity.dispatchActivityResult(Activity.java:5535) 09-01 22:34:50.151 20063-20063/com.example.peyu.bellatrix_01b W/System.err: at android.app.ActivityThread.deliverResults(ActivityThread.java:3588) 09-01 22:34:50.151 20063-20063/com.example.peyu.bellatrix_01b W/System.err: ... 11 more 09-01 22:34:50.151 20063-20063/com.example.peyu.bellatrix_01b W/dalvikvm: threadid=1: calling UncaughtExceptionHandler 09-01 22:34:50.157 20063-20063/com.example.peyu.bellatrix_01b E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.peyu.bellatrix_01b, PID: 20063 java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=100, result=-1, data=Intent { dat=content://media/external/images/media/89391 flg=0x1 }} to activity {com.example.peyu.bellatrix_01b/com.example.peyu.bellatrix_01b.ImageActivity}: java.lang.NullPointerException at android.app.ActivityThread.deliverResults(ActivityThread.java:3592) at android.app.ActivityThread.handleSendResult(ActivityThread.java:3635) at android.app.ActivityThread.access$1300(ActivityThread.java:151) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1390) at android.os.Handler.dispatchMessage(Handler.java:110) at android.os.Looper.loop(Looper.java:193) at android.app.ActivityThread.main(ActivityThread.java:5333) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.NullPointerException at com.example.peyu.bellatrix_01b.ImageActivity.onActivityResult(ImageActivity.java:70) at android.app.Activity.dispatchActivityResult(Activity.java:5535) at android.app.ActivityThread.deliverResults(ActivityThread.java:3588) at android.app.ActivityThread.handleSendResult(ActivityThread.java:3635)  at android.app.ActivityThread.access$1300(ActivityThread.java:151)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1390)  at android.os.Handler.dispatchMessage(Handler.java:110)  at android.os.Looper.loop(Looper.java:193)  at android.app.ActivityThread.main(ActivityThread.java:5333)  at java.lang.reflect.Method.invokeNative(Native Method)  at java.lang.reflect.Method.invoke(Method.java:515)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640)  at dalvik.system.NativeStart.main(Native Method) 



Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
This Question have been answered
HERE


This post first appeared on Stack Solved, please read the originial post: here

Share the post

SOLVED: Android 4.0 crush after loading image in imageView

×

Subscribe to Stack Solved

Get updates delivered right to your inbox!

Thank you for your subscription

×