ImagePicker icon indicating copy to clipboard operation
ImagePicker copied to clipboard

Crash when trying to get Image

Open ajilo297 opened this issue 7 years ago • 7 comments

I am trying to run this code

ImagePicker.pickImage(RegisterActivity.this);

But the app crashes with this error

Attempt to invoke virtual method 'android.content.res.XmlResourceParser android.content.pm.ProviderInfo.loadXmlMetaData(android.content.pm.PackageManager, java.lang.String)' on a null object reference

Here is the full log if you need it

java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.XmlResourceParser android.content.pm.ProviderInfo.loadXmlMetaData(android.content.pm.PackageManager, java.lang.String)' on a null object reference
        at android.support.v4.content.FileProvider.parsePathStrategy(FileProvider.java:604)
        at android.support.v4.content.FileProvider.getPathStrategy(FileProvider.java:578)
        at android.support.v4.content.FileProvider.getUriForFile(FileProvider.java:416)
        at com.mvc.imagepicker.ImagePicker.getPickImageIntent(ImagePicker.java:219)
        at com.mvc.imagepicker.ImagePicker.startChooser(ImagePicker.java:189)
        at com.mvc.imagepicker.ImagePicker.pickImage(ImagePicker.java:180)
        at com.mvc.imagepicker.ImagePicker.pickImage(ImagePicker.java:88)
        at com.altorumleren.food4u.modules.signin_signup.signup.RegisterActivity.showImagePicker(RegisterActivity.java:312)
        at com.altorumleren.food4u.modules.signin_signup.signup.EnterDetailsFragment.getImage(EnterDetailsFragment.java:123)
        at com.altorumleren.food4u.modules.signin_signup.signup.EnterDetailsFragment.onClick(EnterDetailsFragment.java:117)
        at android.view.View.performClick(View.java:6256)
        at android.view.View$PerformClick.run(View.java:24701)
        at android.os.Handler.handleCallback(Handler.java:789)
        at android.os.Handler.dispatchMessage(Handler.java:98)
        at android.os.Looper.loop(Looper.java:172)

ajilo297 avatar May 25 '18 10:05 ajilo297

Getting exact same error. I think this has to do with the fact that I have added tools:replace lines as suggested by android studio in already-existing file provider authroity declaration in AndroidManifest.xml, otherwise the build fails:

    <provider
        tools:replace="android:authorities"
        android:name="android.support.v4.content.FileProvider"
        android:authorities="${applicationId}.fileprovider"
        android:exported="false"
        android:grantUriPermissions="true">
        <meta-data
            tools:replace="android:resource"
            android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/file_paths" />
    </provider>

axper avatar Jun 09 '18 16:06 axper

EDIT: THis does not work.

There's a pull request that fixes this: https://github.com/Mariovc/ImagePicker/pull/46 but before it gets merged, you can use my fork of this repo: https://jitpack.io/#axper/ImagePicker/1.2.5

axper avatar Jun 10 '18 05:06 axper

@axper i tried adding that didnt worked even build successfully.Then i get your dependency https://jitpack.io/#axper/ImagePicker/1.2.5 but app still crashes with same error given by @ajilo297 . my heads are off man just tell me where am i getting wrong.

git1998 avatar Jun 19 '18 12:06 git1998

@git1998 Hey you are right, I was never really able to fix this issue and moved to much stabler and easier EasyImage library: https://github.com/jkwiecien/EasyImage

axper avatar Jun 19 '18 12:06 axper

add permission for camera in menifest or runtime , and adding in manifest will definatly solve this issue.It worked for me

git1998 avatar Jun 19 '18 12:06 git1998

@axper thanks for reply.I will also gonna try EasyImage.

git1998 avatar Jun 19 '18 12:06 git1998

@git1998 @axper try this why waiting for official fix implementation 'com.github.songpr:ImagePicker:e2b4383' I've been using this instead for 9 months already

songpr avatar Nov 07 '18 07:11 songpr