FileProvider.getUriForFile 报错 空指针

2019-12-17 17:22:08.267 3635-3635/com.xz.cfw 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
2019-12-17 17:22:08.267 3635-3635/com.xz.cfw W/System.err:     at androidx.core.content.FileProvider.parsePathStrategy(FileProvider.java:605)
2019-12-17 17:22:08.267 3635-3635/com.xz.cfw W/System.err:     at androidx.core.content.FileProvider.getPathStrategy(FileProvider.java:579)
2019-12-17 17:22:08.267 3635-3635/com.xz.cfw W/System.err:     at androidx.core.content.FileProvider.getUriForFile(FileProvider.java:417)
2019-12-17 17:22:08.267 3635-3635/com.xz.cfw W/System.err:     at com.xz.video.util.MultiMediaUtils.viewVideo(MultiMediaUtils.java:39)
2019-12-17 17:22:08.268 3635-3635/com.xz.cfw W/System.err:     at com.xz.cfw.ui.activity.MainActivity.lambda$setListener$0$MainActivity(MainActivity.java:66)
2019-12-17 17:22:08.268 3635-3635/com.xz.cfw W/System.err:     at com.xz.cfw.ui.activity.-$$Lambda$MainActivity$qN5t8YkJM-qrbPddZglG05uhojM.onClick(Unknown Source:2)
2019-12-17 17:22:08.268 3635-3635/com.xz.cfw W/System.err:     at android.view.View.performClick(View.java:6663)
2019-12-17 17:22:08.268 3635-3635/com.xz.cfw W/System.err:     at android.view.View.performClickInternal(View.java:6635)
2019-12-17 17:22:08.268 3635-3635/com.xz.cfw W/System.err:     at android.view.View.access$3100(View.java:794)
2019-12-17 17:22:08.268 3635-3635/com.xz.cfw W/System.err:     at android.view.View$PerformClick.run(View.java:26199)
2019-12-17 17:22:08.268 3635-3635/com.xz.cfw W/System.err:     at android.os.Handler.handleCallback(Handler.java:907)
2019-12-17 17:22:08.268 3635-3635/com.xz.cfw W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:105)
2019-12-17 17:22:08.268 3635-3635/com.xz.cfw W/System.err:     at android.os.Looper.loop(Looper.java:216)
2019-12-17 17:22:08.268 3635-3635/com.xz.cfw W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:7593)
2019-12-17 17:22:08.268 3635-3635/com.xz.cfw W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
2019-12-17 17:22:08.268 3635-3635/com.xz.cfw W/System.err:     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524)
2019-12-17 17:22:08.269 3635-3635/com.xz.cfw W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:987)

这是我当前报的错,原来我项目拷过来的,原项目就不报错,现在我是用的组件化结果报错了。

看我原来配置

 public void viewVideo(String photoPath) {
        try {
            if (FileUtilvv.isExistsFile(photoPath)) {
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                File file = new File(photoPath);
                //判断是否是AndroidN以及更高的版本
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                    Uri contentUri = FileProvider.getUriForFile(mContext, getPackageName() + ".fileprovider", FileUtilvv
                            .createFile(photoPath));
                    intent.setDataAndType(contentUri, "video/*");
                    //给目标应用一个临时的授权
                    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                } else {
                    intent.setDataAndType(Uri.fromFile(file), "video/*");
                }
                startActivity(intent);
            } else {
                T.error(mContext, "视频不存在,请重新录制.");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

注册文件里面的配置: 

 
            
        

问题就出现在这个.fileProvider  去掉就行了,至于为什么我也没深研究.

有遇到的同学可以参考配置。

 

你可能感兴趣的:(android,基础)