Android 7.0,8.0拍照loadXmlMetaData(XXXX, java.lang.String)' on a null object reference

久未见 提交于 2019-12-05 17:50:26
 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.xiaoluobei.facedetection.view.activity.FaceBlackInsertOrUpdateActivity$3.onClick(FaceBlackInsertOrUpdateActivity.java:262)
        at android.support.v7.app.AlertController$AlertParams$3.onItemClick(AlertController.java:1067)
        at android.widget.AdapterView.performItemClick(AdapterView.java:313)
        at android.widget.AbsListView.performItemClick(AbsListView.jav

      这个错多半是出在provider的包名部分写错了导致没找到报空了,从第4行的日志定位到FaceBlackInsertOrUpdateActivity.java类262行,代码是:

  phototUri = FileProvider.getUriForFile(
                                    context,
                                    context.getPackageName() + ".fileprovider",
                                    cameraPhoto);

      打断点一看,context.getPackageName()得到的跟manifest得到的包名并不一致,费解,故代码改为:

phototUri = FileProvider.getUriForFile(
                                    context,
                                    "com.xiaoluobei.facedetection.fileproviders",
                                    cameraPhoto);

     好用了。

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!