I am developing an application for Android which is supposed to take pictures from camera and upload those images to database. However, the app runs fine for first 8-10 pictures, but when I attempt to take more pictures the app gets crashed.
The error from log
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.project.salesservice, PID: 18379
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { act=inline-data (has extras) }} to activity {com.project.salesservice/com.project.salesservice.user.UserVisitDetailActivity}: java.lang.NullPointerException: uriString
at android.app.ActivityThread.deliverResults(ActivityThread.java:5195)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:5236)
at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:51)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2187)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:236)
at android.app.ActivityThread.main(ActivityThread.java:8057)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:620)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1011)
Caused by: java.lang.NullPointerException: uriString
at android.net.Uri$StringUri.<init>(Uri.java:496)
at android.net.Uri$StringUri.<init>(Uri.java:486)
at android.net.Uri.parse(Uri.java:458)
at com.project.salesservice.user.UserVisitDetailActivity.getImageUri(UserVisitDetailActivity.java:582)
at com.project.salesservice.user.UserVisitDetailActivity.onActivityResult(UserVisitDetailActivity.java:558)
at android.app.Activity.dispatchActivityResult(Activity.java:8516)
at android.app.ActivityThread.deliverResults(ActivityThread.java:5188)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:5236)
at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:51)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2187)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:236)
at android.app.ActivityThread.main(ActivityThread.java:8057)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:620)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1011)
Code for starting intent
imageUri = null;
Intent takePictureIntent = new Intent();
takePictureIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, imageUri);
takePictureIntent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
On Activity Result Code
#Override
public void onActivityResult(int requestCode, int resultCode, #Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == REQUEST_IMAGE_CAPTURE && resultCode == UserVisitDetailActivity.RESULT_OK && data != null){
System.out.println("Masuk Camera");
Bitmap photo = (Bitmap) data.getExtras().get("data");
imageUri = getImageUri(getApplicationContext(), photo);
if(checkInOut.getText().equals("Check In")) {
System.out.println(imageUri);
checkInHolder.setVisibility(View.VISIBLE);
checkInHolder.setImageURI(imageUri);
} else if(checkInHolder.getVisibility() == View.VISIBLE && checkInOut.getText().equals("Check Out")) {
System.out.println(imageUri);
checkOutHolder.setVisibility(View.VISIBLE);
checkOutHolder.setImageURI(imageUri);
}
}
}
Get Image URI Code
public Uri getImageUri(Context inContext, Bitmap inImage) {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
String path = MediaStore.Images.Media.insertImage(inContext.getContentResolver(), inImage, "Title", null);
return Uri.parse(path);
}
The problem is solved when the photos stored in the gallery are deleted. And the app will start to crash again if the photos reach 10 in gallery. Sorry if my grammar is not correct.
Really appreciate for your help. Thank you
Maybe you can optimize your image taking. The lack of memory on the device may be one of the cause of this problem. If there is not enough memory, the program may crash since taking pictures uses up memory. You might think about compressing the pictures before submitting them to the database or putting in place a system that releases memory after each picture is taken to solve this problem.
You could also check if the call to the MediaStore.Images.Media.insertImage method returns an empty string which is then passed to the Uri.parse method causing a NullPointerException. You should check if the MediaStore.Images.Media.insertImage method actually returns a valid value. If it does not, you should consider using another method to insert the image into the internal storage.
Related
I am selecting a image from gallery and trying to covert it into pdf using itext , but when i selecting the image its app crashes with null pointer excetion
when i logged the picture path getting null( String picturePath = cursor.getString(columnIndex);)
code for the same
final private int SELECT_PICTURE = 201;
select_img.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,"Select Picture"), SELECT_PICTURE);
}
});
protected void onActivityResult(int requestCode, int resultCode, #Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
switch(requestCode){
case SELECT_PICTURE:
Uri selectedImageUri = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(selectedImageUri,filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
cursor.close();
Bitmap bmp = BitmapFactory.decodeFile(picturePath);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
error
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=201, result=-1, data=Intent { dat=content://com.android.providers.media.documents/document/image:87703 flg=0x1 }} to activity {com.example.pdfcreator/com.example.pdfcreator.MainActivity}: 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:4423)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4465)
at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:49)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1831)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:201)
at android.app.ActivityThread.main(ActivityThread.java:6810)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)
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.pdfcreator.MainActivity.onActivityResult(MainActivity.java:159)
at android.app.Activity.dispatchActivityResult(Activity.java:7590)
at android.app.ActivityThread.deliverResults(ActivityThread.java:441
solved Intent.ACTION_PICK solved my issue.
i was using this answer How to convert images to pdf using iText , as he used action ACTION_GET_CONTENT
can any one tell me why ACTION_GET_CONTENT not working here?
My Android app wants to create a folder in Google Drive and get the uri from the Drive app on the device.
It sends an intent, you can see the code below:
private void createFolder(String folderName) {
Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
// Create a file with the requested MIME type.
intent.setType("vnd.android.document/directory");
intent.putExtra(Intent.EXTRA_TITLE, folderName);
startActivityForResult(intent, WRITE_REQUEST_CODE);
}
then it gets the returned data, you can see the code below:
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent resultData)
{
if (requestCode == WRITE_REQUEST_CODE && resultCode == Activity.RESULT_OK) {
Uri uri = null;
if (resultData != null) {
uri = resultData.getData();
Log.i("result", "Uri: " + uri.toString());
DocumentFile pickedDir = DocumentFile.fromTreeUri(this, uri); //this line gives the error
}
}
}
I used a mimetype found on the internet that seems to be a standard type. The same error is issued when using "application/vnd.google-apps.folder".
The goal is to have a document tree but in logcat I get the following error:
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=43, result=-1, data=Intent { dat=content://com.google.android.apps.docs.storage/document/acc=1;doc=encoded=LongStringWithRandomCharactersHere/j flg=0x43 }} to activity {com.example.myapplication/com.example.myapplication.MainActivity}: java.lang.IllegalArgumentException: Invalid URI: content://com.google.android.apps.docs.storage/document/acc%3D1%3Bdoc%3Dencoded%3DSameLongStringWithRandomCharactersHere%2Fj
and below
Caused by: java.lang.IllegalArgumentException: Invalid URI: content://com.google.android.apps.docs.storage/document/acc%3D1%3Bdoc%3Dencoded%3DAnotherLongStringWithDifferentRandomDataHere
Here's the complete stack trace:
2019-05-31 15:06:50.167 31184-31184/com.example.myapplication E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.myapplication, PID: 31184
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=43, result=-1, data=Intent { dat=content://com.google.android.apps.docs.storage/document/acc=1;doc=encoded=randomcharacters flg=0x43 }} to activity {com.example.myapplication/com.example.myapplication.MainActivity}: java.lang.IllegalArgumentException: Invalid URI: content://com.google.android.apps.docs.storage/document/acc%3D1%3Bdoc%3Dencoded%3Drandomcharacters
at android.app.ActivityThread.deliverResults(ActivityThread.java:4365)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4409)
at android.app.ActivityThread.-wrap19(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1670)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6687)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:810)
Caused by: java.lang.IllegalArgumentException: Invalid URI: content://com.google.android.apps.docs.storage/document/acc%3D1%3Bdoc%3Dencoded%3Drandomcharacters
at android.provider.DocumentsContract.getTreeDocumentId(DocumentsContract.java:1023)
at android.support.v4.provider.DocumentFile.fromTreeUri(DocumentFile.java:138)
at com.example.myapplication.MainActivity.onActivityResult(MainActivity.java:254)
at android.app.Activity.dispatchActivityResult(Activity.java:7295)
at android.app.ActivityThread.deliverResults(ActivityThread.java:4361)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4409)
at android.app.ActivityThread.-wrap19(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1670)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6687)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:810)
The uri is not wrong because I can further extract the name of the folder (and the size=0), that is successfully created on the Drive cloud.
What's wrong instead? It seems that my app cannot handle it as a document tree.
This is working with Google Drive cloud space but maybe it's a hack. It is not guaranteed to always work.
This example creates a cloud file in a cloud folder that was created by the user (the SAF picker is opened by the app).
Creating the cloud folder (the user has to select the cloud root first from the picker UI)
Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
intent.setType("vnd.android.document/directory");
intent.addFlags(Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
startActivityForResult(intent, CREATE_DIRECTORY_REQUEST_CODE);
onActivityResult
#Override
protected void onActivityResult(int requestCode,int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == CREATE_DIRECTORY_REQUEST_CODE)
{
if (resultCode == Activity.RESULT_OK) {
int takeFlags = data.getFlags()
&
(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
ContentResolver resolver = this.getContentResolver();
resolver.takePersistableUriPermission(data.getData(),takeFlags);
archiveUri(data.getData().toString()); //important to save the toString() result, not getPath()
archiveAuthority(data.getData().getAuthority());
}
else
{
// The user cancelled the request.
}
}
}
using the Uri next time
ContentResolver contentResolver;
contentResolver = this.getContentResolver();
uriPath=retrieveArchivedUri();
Uri tempUri;
Uri uri;
String authority;
tempUri=Uri.parse(uriPath);
authority=retrieveArchivedAuthority();
uri= DocumentsContract.buildDocumentUri(authority,
DocumentsContract.getDocumentId(tempUri)); //folder Uri
try
{
DocumentsContract.createDocument(contentResolver,uri,"plain/text","fileName");
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
I'm following a tutorial to load some images using uri and picasso method, it works until you select the image and then the application crash.
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.johan.portfolijs, PID: 13364
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { dat=content://com.android.providers.media.documents/document/image:17998 flg=0x1 }} to activity {com.example.johan.portfolijs/com.example.johan.portfolijs.MainActivity}: java.lang.ClassCastException: android.net.Uri$HierarchicalUri cannot be cast to com.squareup.picasso.Target
at android.app.ActivityThread.deliverResults(ActivityThread.java:4605)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4647)
at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:49)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1948)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7045)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:964)
Caused by: java.lang.ClassCastException: android.net.Uri$HierarchicalUri cannot be cast to com.squareup.picasso.Target
at com.example.johan.portfolijs.MainActivity.onActivityResult(MainActivity.java:87)
at android.app.Activity.dispatchActivityResult(Activity.java:7759)
Here you are getting the class cast exception while assigning it to URI, so check the code again .
Try this,
data.getData().getPath()
or
Uri selectedImageURI = data.getData()
Adding this first conditional should work:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode != RESULT_CANCELED) {
if (requestCode == CAMERA_REQUEST) {
Bitmap photo = (Bitmap) data.getExtras().get("data");
imageView.setImageBitmap(photo);
}
}
}
I'm using Photo Editor SDK for Android application with React Native. Application crashes when either photo is chosen from the gallery or taken with camera. Tested on Android 8.1, 5, and 6. We are using v5 of the PESDK library and targetSdkVersion 27.
In MainActivity we have
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == PESDK_EDITOR_REQUEST && resultCode == Activity.RESULT_OK) {
String resultPath = data.getStringExtra(ImgLyIntent.RESULT_IMAGE_PATH);
//...
}
}
It crashes on the data.getStringExtra() line. Here is the stacktrace:
Fatal Exception: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=12345678, result=-1, data=Intent { (has extras) }} to activity {com.***/com.***.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.ClassLoader java.lang.Class.getClassLoader()' on a null object reference
at android.app.ActivityThread.deliverResults(ActivityThread.java:4440)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4484)
at android.app.ActivityThread.-wrap19(Unknown Source)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1743)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6753)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:482)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.ClassLoader java.lang.Class.getClassLoader()' on a null object reference
at ly.img.android.sdk.models.state.manager.SettingsList.<init>(SettingsList.java:93)
at ly.img.android.sdk.models.state.manager.SettingsList$1.createFromParcel(SettingsList.java:44)
at ly.img.android.sdk.models.state.manager.SettingsList$1.createFromParcel(SettingsList.java:41)
at android.os.Parcel.readParcelable(Parcel.java:2851)
at android.os.Parcel.readValue(Parcel.java:2745)
at android.os.Parcel.readArrayMapInternal(Parcel.java:3114)
at android.os.BaseBundle.initializeFromParcelLocked(BaseBundle.java:273)
at android.os.BaseBundle.unparcel(BaseBundle.java:226)
at android.os.BaseBundle.getString(BaseBundle.java:1118)
at android.content.Intent.getStringExtra(Intent.java:7139)
at com.***.MainActivity.onActivityResult(MainActivity.java:46)
at android.app.Activity.dispatchActivityResult(Activity.java:7312)
at android.app.ActivityThread.deliverResults(ActivityThread.java:4436)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4484)
at android.app.ActivityThread.-wrap19(Unknown Source)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1743)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6753)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:482)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
NPE is thrown from the library. I have simply followed the tutorial, I don't know what am I doing wrong. Any help would be appreciated.
This question already has answers here:
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 5 years ago.
I have an app and I need to take photos and then upload it to firebase. I basically need Uri path of the photo taken.
I read Get file path of image on Android, but I have a problem with NullPointerException.
Main difference between my problem and the problem above is that I'm doing it in a Fragment.
Here is my code:
mTakePhotoButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
}
});
I get NullPointerException in line with Uri imgUri.
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == CAMERA_REQUEST && resultCode == Activity.RESULT_OK) {
Bitmap photo = (Bitmap) data.getExtras().get("data");
mImgView.setImageBitmap(photo);
Uri imgUri = getImageUri(getActivity().getApplicationContext(), photo);
mManager.setPhotoUri(imgUri);
}
}
And here is the method I use to get Uri.
private Uri getImageUri(Context inContext, Bitmap inImage) {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
inImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
String path = MediaStore.Images.Media.insertImage(inContext.getContentResolver(), inImage, "Title", null);
return Uri.parse(path);
}
The exact error message is:
java.lang.RuntimeException: Failure delivering result
ResultInfo{who=android:fragment:1, request=22222, result=-1,
data=Intent { act=inline-data (has extras) }} to activity
{.MainActivity}:
java.lang.NullPointerException: uriString
I would appreciate any help.
The entire error log:
09-14 12:06:18.448 16497-16497/com.example.radzik.recipes E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.radzik.recipes, PID: 16497
java.lang.RuntimeException: Failure delivering result ResultInfo{who=android:fragment:1, request=22222, result=-1, data=Intent { act=inline-data (has extras) }} to activity {com.example.radzik.recipes/com.example.radzik.recipes.activity.MainActivity}: java.lang.NullPointerException: uriString
at android.app.ActivityThread.deliverResults(ActivityThread.java:3699)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:3742)
at android.app.ActivityThread.-wrap16(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1393)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.NullPointerException: uriString
at android.net.Uri$StringUri.(Uri.java:475)
at android.net.Uri$StringUri.(Uri.java)
at android.net.Uri.parse(Uri.java:437)
at com.example.radzik.recipes.fragment.ChoosePhotoFragment.getImageUri(ChoosePhotoFragment.java:144)
at com.example.radzik.recipes.fragment.ChoosePhotoFragment.onActivityResult(ChoosePhotoFragment.java:135)
at android.app.Activity.dispatchActivityResult(Activity.java:6452)
at android.app.ActivityThread.deliverResults(ActivityThread.java:3695)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:3742)
at android.app.ActivityThread.-wrap16(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1393)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Your problem is with getActivity() becasue you are getting the intent of the current activity you were on which will fail.
So if you move your code to the OnActivityResult this will make it work.
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
//first call super
super.onActivityResult(requestCode, resultCode, data);
//rest of your code
}
Don't forget to add
<uses-permission android:name="android.permission.CAMERA" />
and/or without depends on your app
<uses-feature android:name="android.hardware.camera" />