Attempt to invoke virtual method android content res xmlresourceparser

Error: java.lang.NullPointerException: Attempt to invoke virtual method ‘android.content.res.XmlResourceParser

I am getting this error.I am new to android studio and i need to create this plugin for unity to install an apk at runtime

Error — Attempt to invoke virtual method ‘android.content.Context Android.content.Context.getApplicationContext()’ on a null object reference

EDIT — Plugin Class

EDIT

1 Answer 1

The Contect from Java plugin is null . If you need it, you have to send Unity’s context to the Java plugin.

Add a another parameter that receives the Context then use that Context from the parameter not the one from Android.content.Context.getApplicationContext() .

Java:

C#:

Send the Unity Context and the path you want to pass to the function.

You may have other unrelated error but the Context null problem should be gone.

EDIT:

If you get the Exception:

Attempt to invoke virtual method ‘android.content.res.XmlResourceParser android.content.pm.packageItemInfo.loadXmlMetaData(android.c‌​ontent.pm.PackageMan‌​ager.java.lang.Strin‌​g)’

You have to do few things.

1.Put the «.jar» Plugin your UnityProject/Assets/Plugins/Android directory.

2.Copy «android-support-v4.jar» from your «AndroidSDK/extras/android/support/v4/android-support-v4.jar» directory to your «UnityProject/Assets/Plugins/Android» directory.

Источник

Error: 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 #598

Comments

riansyaaah commented Feb 1, 2018

Version

«react-native»: «^0.52.0»,
«react-native-image-crop-picker»: «^0.19.1»,

Читайте также:  Как исправить система андроида

Platform

gradel
dependencies <
classpath ‘com.android.tools.build:gradle:2.2.3’
>

The text was updated successfully, but these errors were encountered:

riansyaaah commented Feb 1, 2018

its same issue if use distributionUrl=https://services.gradle.org/distributions/gradle-2.14.1-all.zip

OzoTek commented Feb 12, 2018

Same issue here after upgrading React Native.
Did you find a workaround / solution @riansyaaah?

riansyaaah commented Feb 13, 2018

@OzoTek i create new project React Native and move my script on old project to new project. That bad solution but its work for me

drmas commented Feb 26, 2018

add this to your AndroidManifest.xml file

and add this to your android/app/main/res/xml/provider_paths.xml

hycwong commented Feb 27, 2018 •

I tried once more and finally got it work

  1. add this to your AndroidManifest.xml file (between the and tags)
  1. and add this to your android/app/main/res/xml/provider_paths.xml

WosLovesLife commented Mar 2, 2018

I used the above’s code, but still have a error

element at AndroidManifest.xml:37:7 to override «>

So you need add tools:replace=»android:authorities» into

and add the name space for tools:

OzoTek commented Mar 2, 2018

I’m still getting the same behaviour using this solution

Источник

java.lang.NullPointerException: Attempt to invoke virtual method ‘android.content.res.XmlResourceParser #103

Comments

amigax commented Feb 1, 2017

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
02-01 18:11:36.687 1240-1240/uk.co.digpath.merlin W/System.err: at android.support.v4.content.FileProvider.parsePathStrategy(FileProvider.java:560)
02-01 18:11:36.687 1240-1240/uk.co.digpath.merlin W/System.err: at android.support.v4.content.FileProvider.getPathStrategy(FileProvider.java:534)
02-01 18:11:36.687 1240-1240/uk.co.digpath.merlin W/System.err: at android.support.v4.content.FileProvider.getUriForFile(FileProvider.java:376)
02-01 18:11:36.687 1240-1240/uk.co.digpath.merlin W/System.err: at pl.aprilapps.easyphotopicker.EasyImageFiles.getUriToFile(EasyImageFiles.java:142)
02-01 18:11:36.687 1240-1240/uk.co.digpath.merlin W/System.err: at pl.aprilapps.easyphotopicker.EasyImage.createCameraPictureFile(EasyImage.java:56)
02-01 18:11:36.687 1240-1240/uk.co.digpath.merlin W/System.err: at pl.aprilapps.easyphotopicker.EasyImage.createCameraIntent(EasyImage.java:86)

The text was updated successfully, but these errors were encountered:

iagomontenegrob commented May 22, 2017

RuslanTroshkov commented May 26, 2017

Add this code to your manifest file :

pedrofsn commented Oct 2, 2017

filipef101 commented Feb 8, 2018

dibyanshupatnaik commented Mar 2, 2018 •

Hi. I’m new to android programming and am stuck up in a similar way.

As suggested:
android:name=»android.support.v4.content.FileProvider» android:authorities=»$.easyphotopicker.fileprovider»

I have changed those lines in my manifest to:
android:name=»android.support.v4.content.FileProvider» android:authorities=»$.trialcamera.fileprovider»
with my applicationId being com.example.android.trialcamera.

Читайте также:  Через что синхронизируют android

But it seems like I’m making some mistake as I’m getting the same error as above:
Process: com.example.android.trialcamera, PID: 7389
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:584)
at android.support.v4.content.FileProvider.getPathStrategy(FileProvider.java:558)
at android.support.v4.content.FileProvider.getUriForFile(FileProvider.java:400)
at com.example.android.trialcamera.MainActivity.takePicture(MainActivity.java:92)
at com.example.android.trialcamera.MainActivity$1.onClick(MainActivity.java:84)
at android.view.View.performClick(View.java:6294)
at android.view.View$PerformClick.run(View.java:24770)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

And this is the snippet of the code which appears to be a problem:
`public void takePicture(View view) <
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
file = Uri.fromFile(getOutputMediaFile());
file = FileProvider.getUriForFile(MainActivity.this, getApplicationContext().getPackageName()+ «com.example.android.trialcamera», getOutputMediaFile() );
intent.putExtra(MediaStore.EXTRA_OUTPUT, file);

vijayanandkh commented Mar 6, 2018

I think the file path provider path mentioned in manifest and one being used in start activity have different package path. I mean you missed the subpackage «trialcamera» missing.

As i see in Manifest you mentioned:
$.trialcamera.fileprovider»

While in source code accessing the fileprovider using
getApplicationContext().getPackageName()+ «com.example.android.trialcamera»

You can add in source as this way:

FileProvider.getUriForFile(MainActivity.this, getApplicationContext().getPackageName()+ «.trialcamera.fileprovider», getOutputMediaFile() );

or, hard code the package path as

ileProvider.getUriForFile(MainActivity.this, «com.example.android.trialcamera.fileprovider», getOutputMediaFile() );

One thing to look is the authority mentioned in manifest should be same as that being used in source file to get file URI.

Источник

FileProvider crash — npe attempting to invoke XmlResourceParser on a null String

This is a part of my manifest:

This is the filepaths file in raw/xml/filepaths.xml

I download a video from internet and save it to internal storage this way:

I try to use it like so:

I get the following error:

9 Answers 9

The problem was that in Manifest I had this line:

and when calling getUriForFile I was passing:

So changed from «com.example.asd» to «com.example.asd.fileprovider» and it worked

You can do this without hardcoding the package name with an additional benefit of being able to run multiple variants on the same device (think release and debug with applicationIdSuffix , see these issues):

Based on FileProvider.java:560

you were using the wrong authority and it didn’t find the ContentProvider ( info == null ).

Change your manifest to ( $ will be replaced by Manifest Merger)

Читайте также:  Почему гугл запретил хуавей использовать андроид

The .share suffix is optional, in case you have a real ContentProvider which is better to have the package name as the authority.

In my case, I got the error because the

was being imported from

So the string it returned was «android.support.v4» instead of my project package name. Check out the import file is from your import project.Buildconfig and not another. Example:

tag in Manifest I have android:authorities=»$» to always get my project package name as the authority

First, be sure that you provider android:authorities does not conflict with your other providers. Besides that you may choose any name for the last part of its name: «provider», «fileprovider» etc., but app crashes when there are more than one android:authorities listed, while documentation states that it allows multiple values listed.

Источник

FileProvider crash – npe пытается вызвать XmlResourceParser на пустую строку

Это часть моего манифеста:

Это файл filepaths в raw / xml / filepaths.xml

Я загружаю видео из Интернета и сохраняю его во внутреннем хранилище следующим образом:

Я пытаюсь использовать его так:

Я получаю следующую ошибку:

Проблема заключалась в том, что в Manifest у меня была эта строка:

И когда я звонил в getUriForFile, я проходил мимо:

Так что изменилось с «com.example.asd» на «com.example.asd.fileprovider» и это сработало

Вы можете сделать это без жесткого кодирования имени пакета с дополнительным преимуществом, позволяющим запускать несколько вариантов на одном устройстве (подумайте о release и debug с помощью applicationIdSuffix , см. Эти проблемы ):

На основе FileProvider.java:560

Вы использовали неправильный authority и он не нашел ContentProvider ( info == null ).

Измените свой манифест на ( $ будет заменен слиянием манифеста)

Суффикс .share является обязательным, если у вас есть реальный ContentProvider который лучше иметь имя пакета в качестве полномочий.

Во-первых, убедитесь, что поставщик android:authorities не конфликтуют с вашими другими провайдерами. Кроме того, вы можете выбрать любое имя для последней части своего имени: «поставщик», «файлпровайдер» и т. Д., Но приложение выходит из строя, когда имеется несколько android:authorities перечислены, тогда как документация заявляет, что она позволяет перечислять несколько значений.

Источник

Оцените статью