FileProvider failing to parse XML
I am trying to use a FileProvider
but it is failing to parse the XML and throwing this error:
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
This is the calling code:
Log.i(TAG, "Completed download of update file");
statusMessage = "Completed download of update file";
Uri uri;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
if (context != null) {
Log.i(TAG, "Context is: " + context.toString());
} else {
Log.w(TAG, "Context is null");
}
if (context.getString(R.string.file_provider_authority) != null) {
Log.i(TAG, "Authority is: " + context.getString(R.string.file_provider_authority));
} else {
Log.w(TAG, "Authority is null");
}
if (outputFile != null) {
Log.i(TAG, "outputFile is: " + outputFile.toString());
} else {
Log.w(TAG, "outputFile is null");
}
uri = FileProvider.getUriForFile(context, context.getString(R.string.file_provider_authority), outputFile);
statusMessage = "uri set";
} else {
uri = Uri.fromFile(outputFile);
}
Log.i(TAG, "URI successfully set");
statusMessage = "URI successfully set";
None of the parameters are null
and "URI successfully set" is never logged. So it seems to me that the problem lies in the XML files.
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="uk.co.letsdelight.letsdelight">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
<uses-permission android:name="android.permission.REQUEST_WRITE_PERMISSION" />
<!-- To auto-complete the email text field in the login form with the user's emails -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<application
android:allowBackup="true"
android:icon="@drawable/icon_trans"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="@strings/file_provider_authority"
android:exported="false"
android:grantUriPermissions="true"
tools:replace="android:authorities">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_provider_paths" />
</provider>
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
<activity android:name=".AboutActivity" />
<activity
android:name=".LoginActivity"
android:label="@string/title_activity_login"
android:parentActivityName=".MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="uk.co.letsdelight.letsdelight.MainActivity" />
</activity>
</application>
</manifest>
file_provider_paths.xml
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<cache-path name="cache" path="." />
</paths>
Any ideas about what I can try to resolve this issue please?
java android android-fileprovider
add a comment |
I am trying to use a FileProvider
but it is failing to parse the XML and throwing this error:
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
This is the calling code:
Log.i(TAG, "Completed download of update file");
statusMessage = "Completed download of update file";
Uri uri;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
if (context != null) {
Log.i(TAG, "Context is: " + context.toString());
} else {
Log.w(TAG, "Context is null");
}
if (context.getString(R.string.file_provider_authority) != null) {
Log.i(TAG, "Authority is: " + context.getString(R.string.file_provider_authority));
} else {
Log.w(TAG, "Authority is null");
}
if (outputFile != null) {
Log.i(TAG, "outputFile is: " + outputFile.toString());
} else {
Log.w(TAG, "outputFile is null");
}
uri = FileProvider.getUriForFile(context, context.getString(R.string.file_provider_authority), outputFile);
statusMessage = "uri set";
} else {
uri = Uri.fromFile(outputFile);
}
Log.i(TAG, "URI successfully set");
statusMessage = "URI successfully set";
None of the parameters are null
and "URI successfully set" is never logged. So it seems to me that the problem lies in the XML files.
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="uk.co.letsdelight.letsdelight">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
<uses-permission android:name="android.permission.REQUEST_WRITE_PERMISSION" />
<!-- To auto-complete the email text field in the login form with the user's emails -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<application
android:allowBackup="true"
android:icon="@drawable/icon_trans"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="@strings/file_provider_authority"
android:exported="false"
android:grantUriPermissions="true"
tools:replace="android:authorities">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_provider_paths" />
</provider>
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
<activity android:name=".AboutActivity" />
<activity
android:name=".LoginActivity"
android:label="@string/title_activity_login"
android:parentActivityName=".MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="uk.co.letsdelight.letsdelight.MainActivity" />
</activity>
</application>
</manifest>
file_provider_paths.xml
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<cache-path name="cache" path="." />
</paths>
Any ideas about what I can try to resolve this issue please?
java android android-fileprovider
1
That Exception can happen when you callFileProvider.getUriForFile()
with an authority that doesn't match the value in the manifest. Your value there looks suspect –@strings/file_provider_authority
. Why isstrings
plural? Normally, it's@string
. Do you somehow have two differentfile_provider_authority
values? Are you getting an error or warning on that line?
– Mike M.
Nov 22 '18 at 22:18
Changing fromstrings
tostring
has solved the problem - many thanks. But why is it singular when the XML file isres/values/strings.xml
which is plural?
– İan Boddison
Nov 22 '18 at 23:13
1
I explain that in my answer here. It's specifically aboutattr
resources, but it's the same forstring
resources, as well. I'm kinda surprised that built successfully, actually, but I suppose you can do all sorts of odd stuff with Gradle.
– Mike M.
Nov 22 '18 at 23:31
add a comment |
I am trying to use a FileProvider
but it is failing to parse the XML and throwing this error:
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
This is the calling code:
Log.i(TAG, "Completed download of update file");
statusMessage = "Completed download of update file";
Uri uri;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
if (context != null) {
Log.i(TAG, "Context is: " + context.toString());
} else {
Log.w(TAG, "Context is null");
}
if (context.getString(R.string.file_provider_authority) != null) {
Log.i(TAG, "Authority is: " + context.getString(R.string.file_provider_authority));
} else {
Log.w(TAG, "Authority is null");
}
if (outputFile != null) {
Log.i(TAG, "outputFile is: " + outputFile.toString());
} else {
Log.w(TAG, "outputFile is null");
}
uri = FileProvider.getUriForFile(context, context.getString(R.string.file_provider_authority), outputFile);
statusMessage = "uri set";
} else {
uri = Uri.fromFile(outputFile);
}
Log.i(TAG, "URI successfully set");
statusMessage = "URI successfully set";
None of the parameters are null
and "URI successfully set" is never logged. So it seems to me that the problem lies in the XML files.
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="uk.co.letsdelight.letsdelight">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
<uses-permission android:name="android.permission.REQUEST_WRITE_PERMISSION" />
<!-- To auto-complete the email text field in the login form with the user's emails -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<application
android:allowBackup="true"
android:icon="@drawable/icon_trans"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="@strings/file_provider_authority"
android:exported="false"
android:grantUriPermissions="true"
tools:replace="android:authorities">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_provider_paths" />
</provider>
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
<activity android:name=".AboutActivity" />
<activity
android:name=".LoginActivity"
android:label="@string/title_activity_login"
android:parentActivityName=".MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="uk.co.letsdelight.letsdelight.MainActivity" />
</activity>
</application>
</manifest>
file_provider_paths.xml
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<cache-path name="cache" path="." />
</paths>
Any ideas about what I can try to resolve this issue please?
java android android-fileprovider
I am trying to use a FileProvider
but it is failing to parse the XML and throwing this error:
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
This is the calling code:
Log.i(TAG, "Completed download of update file");
statusMessage = "Completed download of update file";
Uri uri;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
if (context != null) {
Log.i(TAG, "Context is: " + context.toString());
} else {
Log.w(TAG, "Context is null");
}
if (context.getString(R.string.file_provider_authority) != null) {
Log.i(TAG, "Authority is: " + context.getString(R.string.file_provider_authority));
} else {
Log.w(TAG, "Authority is null");
}
if (outputFile != null) {
Log.i(TAG, "outputFile is: " + outputFile.toString());
} else {
Log.w(TAG, "outputFile is null");
}
uri = FileProvider.getUriForFile(context, context.getString(R.string.file_provider_authority), outputFile);
statusMessage = "uri set";
} else {
uri = Uri.fromFile(outputFile);
}
Log.i(TAG, "URI successfully set");
statusMessage = "URI successfully set";
None of the parameters are null
and "URI successfully set" is never logged. So it seems to me that the problem lies in the XML files.
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="uk.co.letsdelight.letsdelight">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
<uses-permission android:name="android.permission.REQUEST_WRITE_PERMISSION" />
<!-- To auto-complete the email text field in the login form with the user's emails -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<application
android:allowBackup="true"
android:icon="@drawable/icon_trans"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="@strings/file_provider_authority"
android:exported="false"
android:grantUriPermissions="true"
tools:replace="android:authorities">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_provider_paths" />
</provider>
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
<activity android:name=".AboutActivity" />
<activity
android:name=".LoginActivity"
android:label="@string/title_activity_login"
android:parentActivityName=".MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="uk.co.letsdelight.letsdelight.MainActivity" />
</activity>
</application>
</manifest>
file_provider_paths.xml
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<cache-path name="cache" path="." />
</paths>
Any ideas about what I can try to resolve this issue please?
java android android-fileprovider
java android android-fileprovider
asked Nov 22 '18 at 22:00
İan Boddisonİan Boddison
478
478
1
That Exception can happen when you callFileProvider.getUriForFile()
with an authority that doesn't match the value in the manifest. Your value there looks suspect –@strings/file_provider_authority
. Why isstrings
plural? Normally, it's@string
. Do you somehow have two differentfile_provider_authority
values? Are you getting an error or warning on that line?
– Mike M.
Nov 22 '18 at 22:18
Changing fromstrings
tostring
has solved the problem - many thanks. But why is it singular when the XML file isres/values/strings.xml
which is plural?
– İan Boddison
Nov 22 '18 at 23:13
1
I explain that in my answer here. It's specifically aboutattr
resources, but it's the same forstring
resources, as well. I'm kinda surprised that built successfully, actually, but I suppose you can do all sorts of odd stuff with Gradle.
– Mike M.
Nov 22 '18 at 23:31
add a comment |
1
That Exception can happen when you callFileProvider.getUriForFile()
with an authority that doesn't match the value in the manifest. Your value there looks suspect –@strings/file_provider_authority
. Why isstrings
plural? Normally, it's@string
. Do you somehow have two differentfile_provider_authority
values? Are you getting an error or warning on that line?
– Mike M.
Nov 22 '18 at 22:18
Changing fromstrings
tostring
has solved the problem - many thanks. But why is it singular when the XML file isres/values/strings.xml
which is plural?
– İan Boddison
Nov 22 '18 at 23:13
1
I explain that in my answer here. It's specifically aboutattr
resources, but it's the same forstring
resources, as well. I'm kinda surprised that built successfully, actually, but I suppose you can do all sorts of odd stuff with Gradle.
– Mike M.
Nov 22 '18 at 23:31
1
1
That Exception can happen when you call
FileProvider.getUriForFile()
with an authority that doesn't match the value in the manifest. Your value there looks suspect – @strings/file_provider_authority
. Why is strings
plural? Normally, it's @string
. Do you somehow have two different file_provider_authority
values? Are you getting an error or warning on that line?– Mike M.
Nov 22 '18 at 22:18
That Exception can happen when you call
FileProvider.getUriForFile()
with an authority that doesn't match the value in the manifest. Your value there looks suspect – @strings/file_provider_authority
. Why is strings
plural? Normally, it's @string
. Do you somehow have two different file_provider_authority
values? Are you getting an error or warning on that line?– Mike M.
Nov 22 '18 at 22:18
Changing from
strings
to string
has solved the problem - many thanks. But why is it singular when the XML file is res/values/strings.xml
which is plural?– İan Boddison
Nov 22 '18 at 23:13
Changing from
strings
to string
has solved the problem - many thanks. But why is it singular when the XML file is res/values/strings.xml
which is plural?– İan Boddison
Nov 22 '18 at 23:13
1
1
I explain that in my answer here. It's specifically about
attr
resources, but it's the same for string
resources, as well. I'm kinda surprised that built successfully, actually, but I suppose you can do all sorts of odd stuff with Gradle.– Mike M.
Nov 22 '18 at 23:31
I explain that in my answer here. It's specifically about
attr
resources, but it's the same for string
resources, as well. I'm kinda surprised that built successfully, actually, but I suppose you can do all sorts of odd stuff with Gradle.– Mike M.
Nov 22 '18 at 23:31
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53438425%2ffileprovider-failing-to-parse-xml%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53438425%2ffileprovider-failing-to-parse-xml%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
That Exception can happen when you call
FileProvider.getUriForFile()
with an authority that doesn't match the value in the manifest. Your value there looks suspect –@strings/file_provider_authority
. Why isstrings
plural? Normally, it's@string
. Do you somehow have two differentfile_provider_authority
values? Are you getting an error or warning on that line?– Mike M.
Nov 22 '18 at 22:18
Changing from
strings
tostring
has solved the problem - many thanks. But why is it singular when the XML file isres/values/strings.xml
which is plural?– İan Boddison
Nov 22 '18 at 23:13
1
I explain that in my answer here. It's specifically about
attr
resources, but it's the same forstring
resources, as well. I'm kinda surprised that built successfully, actually, but I suppose you can do all sorts of odd stuff with Gradle.– Mike M.
Nov 22 '18 at 23:31