-3

当我执行我的应用程序时,android studio LOGCAT 中出现以下错误。如何解决这个问题呢?

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:605)
        at android.support.v4.content.FileProvider.getPathStrategy(FileProvider.java:579)
        at android.support.v4.content.FileProvider.getUriForFile(FileProvider.java:417)
        at com.google.zxing.client.android.CaptureActivity$18.onClick(CaptureActivity.java:1527)
        at android.view.View.performClick(View.java:6891)
        at android.widget.TextView.performClick(TextView.java:12651)
        at android.view.View$PerformClick.run(View.java:26083)
        at android.os.Handler.handleCallback(Handler.java:789)
        at android.os.Handler.dispatchMessage(Handler.java:98)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6938)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)

我在 AndroidManifest.xml 下面添加了

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

我添加了 privider_paths 文件。

<paths xmlns:android="http://schemas.android.com/apk/res/android">
    <external-path
        name="external_files"
        path="." />
    <root-path
        name="external_files"
        path="/storage/"/>
</paths>

并且错误发生在这一点上

cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, FileProvider.getUriForFile(getApplicationContext(), BuildConfig.APPLICATION_ID+".FileProvider", file));
4

1 回答 1

0

application在你的标签里面试试这个

<application
        android:requestLegacyExternalStorage="true">
</application>
于 2020-01-31T09:48:44.987 回答