Issue
I am using the android cropping library at this github repository.
The following code works correctly when removing the below three lines :
Intent i=new Intent(MainActivity.this,Edit.class);
i.putExtra("imageUri", uri.toString());
startActivity(i);
I am trying to send the following result intent to the second activity :
private void handleCrop(int resultCode, Intent result) {
hideProgress();
if (resultCode == RESULT_OK){
resultView.setImageURI(Crop.getOutput(result));
uri=result.getData();
//result.setData(null);
Intent i=new Intent(MainActivity.this,Edit.class);
i.putExtra("imageUri", uri.toString());
startActivity(i);
}
However, for some reason I am getting the following error :
ERROR: Caused by: java.lang.NullPointerException at com.soundcloud.android.crop.example.MainActivity.handleCrop(MainActivity.java:188)
line 188 is : i.putExtra("imageUri", uri.toString());
How can I properly send the result intent to the second activity and avoid triggering this error?
Solution
Check if the uri
is null or not, like this:
if(uri != null)
i.putExtra("imageUri", uri.toString());
EDIT:
how is it possible to be null?
It is null because the getData() is actually null.
resultview is smoothly get saved to imageview
Well to answer that you can look at the source code of Crop.getOutput(result)
here. From the source code:
public static Uri getOutput(Intent result) {
return result.getParcelableExtra(MediaStore.EXTRA_OUTPUT);
}
So Crop.getOutput(result)
doesn't get the Uri
from getData()
. It gets it using getParcelableExtra()
. So, change your code to this:
private void handleCrop(int resultCode, Intent result) {
hideProgress();
if (resultCode == RESULT_OK){
resultView.setImageURI(Crop.getOutput(result));
uri=result.getParcelableExtra(MediaStore.EXTRA_OUTPUT);
//result.setData(null);
Intent i=new Intent(MainActivity.this,Edit.class);
i.putExtra("imageUri", uri.toString());
startActivity(i);
}
Answered By - Eric B.
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.