美文网首页
Attempt to invoke virtual method

Attempt to invoke virtual method

作者: 远在远方的风yzyfdf | 来源:发表于2020-04-07 15:53 被阅读0次
    日志如下
    
    W/System.err: 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
    W/System.err:     at android.support.v4.content.FileProvider.parsePathStrategy(FileProvider.java:605)
    W/System.err:     at android.support.v4.content.FileProvider.getPathStrategy(FileProvider.java:579)
    W/System.err:     at android.support.v4.content.FileProvider.getUriForFile(FileProvider.java:417)
    
    原因

    AndroidManifest.xml中FileProvider配置的authorities与代码中的不同

            //Manifest
            <provider
                android:name="android.support.v4.content.FileProvider"
                android:authorities="${applicationId}.fileprovider"
                android:exported="false"
                android:grantUriPermissions="true">
                <meta-data
                    android:name="android.support.FILE_PROVIDER_PATHS"
                    android:resource="@xml/file_path"/>
            </provider>
            
           //java
           String authority = activity.getPackageName() + ".fileProvider";
           uri = FileProvider.getUriForFile(activity, authority, takePictureFile);
    

    找了好久 ${applicationId}.fileprovider.fileProvider P一个小写一个大写,改成一致就行

    相关文章

      网友评论

          本文标题:Attempt to invoke virtual method

          本文链接:https://www.haomeiwen.com/subject/wzjnphtx.html