1
<!-- language: none -->    

    04-23 11:47:01.904: E/AndroidRuntime(12396):
    java.lang.RuntimeException: Unable to resume activity {com.t4t.sp/com.t4t.sp.SignUpActivity}:
    java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=111, result=-1, data=Intent { act=content://media/external/images/media/3809 (has extras) }} to activity {com.t4t.sp/com.t4t.sp.SignUpActivity}:
    java.lang.NullPointerException

I am not able to find out why the activity is not able to produce the result,what I want is I am launching an edit intent and after the editing I want to supply the uri to my onactivity result.

Edited :

Here is my code of on create method

`protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGESS);
        setContentView(R.layout.activity_sign_up);

        mUsername=(EditText)findViewById(R.id.usernameField);
        mPassword=(EditText)findViewById(R.id.passwordField);
        mImage=(ImageView) findViewById(R.id.imageView1);
        medit=(Button)findViewById(R.id.edit);
        medit.setVisibility(View.GONE);


        mImage.setOnClickListener(new OnClickListener() {



            @Override
            public void onClick(View v) 
            {




                               Intent choosePhotoIntent=new Intent(Intent.ACTION_GET_CONTENT);              choosePhotoIntent.setType("image/*");
                choosePhotoIntent.putExtra("crop", "true");
                choosePhotoIntent.putExtra("outputX", 128);
                choosePhotoIntent.putExtra("outputY", 128);
                choosePhotoIntent.putExtra("aspectX", 1);
                choosePhotoIntent.putExtra("aspectY", 1);
                choosePhotoIntent.putExtra("scale", true);
                startActivityForResult(choosePhotoIntent, PICK_PHOTO_REQUEST);








            }
        });    


`    

here is my onactivity for result code where i am getting a null value for data as when i am trying to fetch the url its saying null pointer over there :

    @SuppressLint("NewApi")
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    Log.e("resultcode",Integer.toString(resultCode));
    Log.e("requestcode",Integer.toString(requestCode)); 
    String fileType = null;
    if(resultCode==RESULT_OK){
    if(requestCode==PICK_PHOTO_REQUEST)


    {




        medit.setVisibility(View.VISIBLE);
        mImageUri=data.getData();
        String imageUri=getRealPathFromURI(mImageUri);
        mImage.setImageURI(Uri.parse(imageUri));
        }     

@Mighter

2 Answers2

0

in your return url class:

Activity act=this;
Intent returnIntent = new Intent();
//Log.i("class2","uri: "+uri);
returnIntent.setData(uri);
//Log.i("class2","return: "+returnIntent.getData().toString());
act.setResult(Activity.RESULT_OK, returnIntent);  
act.finish();

in the calling class:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
//Log.i("class1","finish");
}

when you start the Editing class.

Intent i=new Intent(this,Editing.class);
//Log.i("class1","start");
this.startActivityForResult(i, 0);

If your code is the same as mine then try adding the log comments to get a better idea of what the problem is.

Michael Kent
  • 383
  • 3
  • 17
  • No actually what i am trying to do is geeting the result back on the same activity in onactivity for result method. @theellipsis – user3519641 Apr 23 '14 at 10:13
  • [looks similar to this question then.](http://stackoverflow.com/questions/6448856/android-camera-intent-how-to-get-full-sized-photo) intent.putExtra(MediaStore.EXTRA_OUTPUT, mImageUri); – Michael Kent Apr 23 '14 at 10:19
  • Actually thats a differnt context in that its about taking images from camera but i am chosing it from gallery – user3519641 Apr 23 '14 at 10:41
  • try : String FilePath = data.getData().getPath(); [src](http://android-er.blogspot.co.uk/2011/03/pick-file-using-intentactiongetcontent.html) – Michael Kent Apr 23 '14 at 10:45
  • I keep on getting the same error 04-23 16:26:17.909: E/AndroidRuntime(2774): Caused by: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=111, result=-1, data=Intent { act=content://media/external/images/media/3828 (has extras) }} to activity {com.t4t.sp/com.t4t.sp.SignUpActivity}: java.lang.NullPointerException – user3519641 Apr 23 '14 at 10:57
  • change if to if(requestCode==PICK_PHOTO_REQUEST&&data!=null), just to check the error occurs inside there and is because data is null. – Michael Kent Apr 23 '14 at 11:13
  • I changed it to the way u said but i keep on getting this error,whats the root cause i am still not able to get – user3519641 Apr 23 '14 at 11:42
  • what outputs do you get for these lines? Log.e("resultcode",Integer.toString(resultCode)); Log.e("requestcode",Integer.toString(requestCode)); – Michael Kent Apr 23 '14 at 11:56
  • put a log above this line medit.setVisibility(View.VISIBLE); something like Log.e("intent",data.toString()); – Michael Kent Apr 23 '14 at 12:03
  • I tried this and i am getting this message 04-23 17:36:14.479: E/intent(5347): Intent { act=content://media/external/images/media/4008 (has extras) } – user3519641 Apr 23 '14 at 12:06
  • [try one of these answers, it looks like you have to receive the url differently as it can be content](http://stackoverflow.com/questions/5568874/how-to-extract-the-file-name-from-uri-returned-from-intent-action-get-content) – Michael Kent Apr 23 '14 at 13:03
0

If you look at the error you are getting:

java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=111, result=-1, data=Intent { act=content://media/external/images/media/3809 (has extras) }} to activity {com.t4t.sp/com.t4t.sp.SignUpActivity}:

You can see the Intent that is being passed as the data argument to onActivityResult():

data=Intent { act=content://media/external/images/media/3809 (has extras) }

This Intent contains extras and an ACTION, but it contains no DATA field. This is why you are getting null when calling data.getData().

The URL you are looking for is being returned in the ACTION (which is kinda stupid IMHO, but that's beside the point). You need to do this instead:

    String imageUri=data.getAction();
    mImage.setImageURI(Uri.parse(imageUri));
David Wasser
  • 93,459
  • 16
  • 209
  • 274
  • Thanks alot i was not able to get what was going wrong,it worked for me now i am able to get the uri of the intended image which i was wanting. @David – user3519641 Apr 24 '14 at 05:49
  • So I don't need to return in action in your opinion then what stupidity i am doing can you let me know actually i am newbie so not much know about it. @David Wasser – user3519641 Apr 24 '14 at 05:57
  • Well, if you are returning an URL it would make more sense to either return it in the "data" field of the `Intent` or simply as a String extra. – David Wasser Apr 24 '14 at 08:47