EasyImagePicker-library
EasyImagePicker-library copied to clipboard
NullPointerException Error
Hello, I'm trying to use this library in a program and when I use the camera and save the picture this error is coming up. could you please help me to solve this issue?
05-07 16:28:51.044 5495-5495/com.example.amirmahmoud.imagepickertest E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.amirmahmoud.imagepickertest, PID: 5495
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=0, result=-1, data=Intent { act=inline-data (has extras) }} to activity {com.example.amirmahmoud.imagepickertest/com.example.amirmahmoud.imagepickertest.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.net.Uri.getPath()' on a null object reference
at android.app.ActivityThread.deliverResults(ActivityThread.java:4090)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4133)
at android.app.ActivityThread.-wrap20(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1534)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6121)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.net.Uri.getPath()' on a null object reference
at com.oswaldogh89.picker.ImagePicker.ChangeVisible(ImagePicker.java:246)
at com.oswaldogh89.picker.ImagePicker.AddNewImage(ImagePicker.java:138)
at com.example.amirmahmoud.imagepickertest.MainActivity.onActivityResult(MainActivity.java:32)
at android.app.Activity.dispatchActivityResult(Activity.java:6935)
at android.app.ActivityThread.deliverResults(ActivityThread.java:4086)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4133)
at android.app.ActivityThread.-wrap20(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1534)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6121)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)
Your code within onActivityResult as it is written? If you make a debug, which contains this variable "imageReturnedIntent".
Can you share me your code?
Thank you for your reply, sure here is my main activity
package com.example.amirmahmoud.imagepickertest;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import com.oswaldogh89.picker.ImagePicker;
public class MainActivity extends AppCompatActivity {
ImagePicker picker;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
picker = (ImagePicker) findViewById(R.id.picker);
picker.setMainactivity(MainActivity.this);
picker.SetBorderImageColor("#075e55");
picker.enableDelateAll(false);
}
protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) {
super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
switch (requestCode) {
case 0:
if (resultCode == RESULT_OK) {
picker.AddNewImage(imageReturnedIntent);
}
break;
case 1:
if (resultCode == RESULT_OK) {
picker.AddNewImage(imageReturnedIntent);
}
break;
}
}
}
and this is my layout
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.amirmahmoud.imagepickertest.MainActivity">
<com.oswaldogh89.picker.ImagePicker
android:id="@+id/picker"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</com.oswaldogh89.picker.ImagePicker>
</android.support.constraint.ConstraintLayout>
What happens if you use a LinearLayout instead of a ConstraintLayout?
https://hastebin.com/odixebayey.xml
still crashes
Is not a problem of the library, is the way the cell phone accesses the camera, which cell version have, I leave a link of possible problems.
1.- Just add android:configChanges="orientation" in my manifest to activities.
2.- Link https://www.google.com.mx/search?q=Failure+delivering+result+ResultInfo+camera&rlz=1C1NHXL_esMX707MX707&oq=Failure+delivering+result+ResultInfo+camera&aqs=chrome..69i57j0l5.1595j0j7&sourceid=chrome&ie=UTF-8
http://stackoverflow.com/questions/35263655/android-camera-error-failure-delivering-result-resultinfo
For this answers, I need to change part of your code right? but your code is compiled and I cant do anything with it.
You need to modify the onActivityResult of your AppCompatActivity, I will try to make an example and I will share it to you.
Looking forward to that.
Hello my friend, Have you got any good news?
I bring a little work, in 10 hours I'll help you with the code.
You can go testing, other ways to apply the onActivityResult, the error is there, not in the library.
I think this is an issue with the library. Most camera apps do not return URI in the intent, therefore you will get a null reference with intent.getData(). This will lead to a crash as there is no null check while setting Uri path = imageReturnedIntent.getData();
update issues in this new release
compile 'com.github.oswaldo89:EasyImagePicker-library:1.0.2'
Hello, I am trying to use the library but getting the following error when I click on "Camera" to take a new picture. I am not sure why it's trying to fetch Image file as I am clicking on camera.
E/AndroidRuntime: FATAL EXCEPTION: main Process: com.admin, PID: 11126 java.lang.IllegalArgumentException: Failed to find configured root that contains /storage/emulated/0/Android/data/com.admin/files/Pictures/JPEG_20190211_001544_822842204.jpg at android.support.v4.content.FileProvider$SimplePathStrategy.getUriForFile(FileProvider.java:712) at android.support.v4.content.FileProvider.getUriForFile(FileProvider.java:401) at com.oswaldogh89.picker.ImagePicker.dispatchTakePictureIntent(ImagePicker.java:373) at com.oswaldogh89.picker.ImagePicker.access$100(ImagePicker.java:38) at com.oswaldogh89.picker.ImagePicker$2.onItemSelected(ImagePicker.java:84) at com.oswaldogh89.picker.DialogOptions$CustomDialog.onClick(DialogOptions.java:220) at android.view.View.performClick(View.java:5333) at android.view.View$PerformClick.run(View.java:21792) at android.os.Handler.handleCallback(Handler.java:815) at android.os.Handler.dispatchMessage(Handler.java:104) at android.os.Looper.loop(Looper.java:207) at android.app.ActivityThread.main(ActivityThread.java:5847) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Thanks in advance