问题:

This is a part of my manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.asd"
android:versionCode="118"
android:versionName="118" > <uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="19" /> <application
android:name="com.example.asd.AsdApplication"
android:allowBackup="true"
android:allowTaskReparenting="true"
android:theme="@style/AsdTheme" >
... <provider
android:name="com.example.asd.database.hq.ContentProviderDB"
android:authorities="ourContentProviderAuthorities" >
</provider>
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.example.asd.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/filepaths" />
</provider> ...
</application> </manifest>

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

<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<files-path name="media"/>
</paths>

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

public static boolean saveInputStreamToInternalStorageFile(Context context, String filename, byte[] dataToWrite, Context ctx) {
FileOutputStream fos;
try {
fos = new FileOutputStream(context.getFilesDir() + File.separator + filename); ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(dataToWrite);
oos.close();
return true;
} catch (FileNotFoundException e) {
e.printStackTrace();
return false;
} catch (IOException e) {
e.printStackTrace();
return false;
}
}

I try to use it like so:

private void playVideoFromDeviceWithWorkaround(String fileName) {

    File newFile = new File(getFilesDir(), fileName);
Uri contentUri = FileProvider.getUriForFile(getApplicationContext(), "com.example.asd", newFile); try {
vvVideoFullscreen.setVideoURI(contentUri);
showMediaControls = true;
playVideo();
} catch (Exception e) {
playVideoFromNetwork();
} }

At this line:

Uri contentUri = FileProvider.getUriForFile(getApplicationContext(), "com.example.asd", newFile); 

I get the following 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
at android.support.v4.content.FileProvider.parsePathStrategy(FileProvider.java:560)
at android.support.v4.content.FileProvider.getPathStrategy(FileProvider.java:534)
at android.support.v4.content.FileProvider.getUriForFile(FileProvider.java:376)

解决方案:

The problem was that in Manifest I had this line:

android:authorities="com.example.asd.fileprovider"

and when calling getUriForFile I was passing:

Uri contentUri = FileProvider.getUriForFile(getApplicationContext(), "com.example.asd", newFile); 

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

android- FileProvider崩溃 - NPE试图调用一个空字符串XmlResourceParser(FileProvider crash - npe attempting to invoke XmlResourceParser on a null String)的更多相关文章

  1. 【Android Developers Training】 94. 创建一个空内容提供器(Content Provider)

    注:本文翻译自Google官方的Android Developers Training文档,译者技术一般,由于喜爱安卓而产生了翻译的念头,纯属个人兴趣爱好. 原文链接:http://developer ...

  2. 【Android Developers Training】 93. 创建一个空验证器

    注:本文翻译自Google官方的Android Developers Training文档,译者技术一般,由于喜爱安卓而产生了翻译的念头,纯属个人兴趣爱好. 原文链接:http://developer ...

  3. 文本框如果不输入任何内容提交过后是一个空字符串还是null

    1.在表单不填就提交的情况下,text类型和textarea类型的表单域,提交到服务端为空 2.checkbox.readio.select等表单域在为不填情况下不会提交到服务器,也就是说服务器接收不 ...

  4. Javascript 中的false、0、null、undefined和空字符串对象

    在Javascript中,我们经常会接触到题目中提到的这5个比较特别的对象——false.0.空字符串.null和undefined.这几个对象很容易用错,因此在使用时必须得小心. 类型检测 我们下来 ...

  5. 【转】Javascript 中的false,零值,null,undefined和空字符串对象

    js 开发中经常会碰到判断是否为空的情况,关于 null 和 undefined 的区别了解的不是很好,刚好看见这篇文章,转过来学习一下,以下是转载正文: 在Javascript中,我们经常会接触到题 ...

  6. Javascript 中的false,零值,null,undefined和空字符串对象

    在Javascript中,我们经常会接触到题目中提到的这5个比较特别的对象--false.0.空字符串.null和undefined.这几个对象很容易用错,因此在使用时必须得小心. 类型检测 我们下来 ...

  7. Java进阶(二十一)java 空字符串与null区别

    java 空字符串与null区别 1.类型 null表示的是一个对象的值,而并不是一个字符串.例如声明一个对象的引用,String a = null ; ""表示的是一个空字符串, ...

  8. Js 中的false,零值,null,undefined和空字符串对象

    转自  http://www.imkevinyang.com/2009/07/javascript-中的false零值nullundefined和空字符串对象.html 在Javascript中,我们 ...

  9. 3-java中String值为空字符串与null的判断方法

    java中String值为空字符串与null的判断方法 2018年01月21日 14:53:45 阅读数:1189 Java空字符串与null的区别 1.类型 null表示的是一个对象的值,而不是一个 ...

随机推荐

  1. 拿什么拯救你,我的代码--c#编码规范实战篇 (转)

    http://www.cnblogs.com/lazio10000/p/5413439.html 此文为译文,原文地址请点击. 本文通过重构一个垃圾代码,阐述了如何写出优秀的代码.开发人员及代码审核人 ...

  2. Silverlight自定义控件开发:仪表盘

    在项目中,由于使用到了活动积温运算,也就是指当日平均气温稳定上升到10℃以上时,大多数农作物才能活跃生长.把大于等于10℃持续期内的日平均气温累加起来,得到的气温总和,叫做活动积温.所以我决定采用do ...

  3. 实现chrome扩展启动本地进程 - 补充

    实现chrome扩展启动本地进程 - 补充 标签: chrome扩展启动本地程序访问本地磁盘 2014-10-17 11:42 6753人阅读 评论(17) 收藏 举报  分类: Chrome Plu ...

  4. TCP建立连接、断开连接以及正常报文的报头和报位的大小

    正常通信报文大小: 以太网的头尾:14字节 IP首部:20字节 TCP首部:20字节 尾部4字节校验 合计:58 三次握手的报文大小: SYN: 70 AYN,ACK:72 ACK: 64 合计:20 ...

  5. 《信息安全系统设计基础》第一次实验报告--Linux 基础入门

    北京电子科技学院(BESTI) 实     验    报     告 课程:信息安全设计基础 班级:1352  姓名:何伟钦  学号:20135223 成绩:            指导教师:娄嘉鹏 ...

  6. [poj3666]Making the Grade(DP/左偏树)

    题目大意:给你一个序列a[1....n],让你求一个序列b[1....n],满足 bi =a && bc,则最小的调整可以是把b变成c. 所以归纳可知上面结论成立. dp[i][j] ...

  7. C#基础知识系列一(goto、i++、三元运算符、ref和out、String和string、重载运算符)

    前言 这两天在网上看到的总结很多,尤其是博客园中的,很多很多,也给了我很多的启发,当然自己也总结过,而且有很多人也给与我一些意见和看法.不管怎样,自己还是先把所谓的基础知识加强巩固下吧. 2014年的 ...

  8. WCF入门(12)

    前言 上次写是小半年前的事情了,还在原来的公司,还在原来的项目,同时认识了不少人.外包公司总是有些不适应的地方,总在很闲和很忙之间徘徊.凌晨2点被客户电话叫醒,只为copy一个文件从一台服务器到另一台 ...

  9. 50个提高PHP编程效率的方法

      用单引号代替双引号来包含字符串,这样做会更快一些.因为PHP会在双引号包围的字符串中搜寻变量,单引号则不会,注意:只有echo能这么做,它是一种可以把多个字符串当作参数的“函数”(译注:PHP手册 ...

  10. OC基础--关键字@property 和 @synthesize

    一.@property关键字需要掌握的知识: 1.用在@interface中,用来自动生成setter和getter的声明 例:@property int age;--相当于执行了右边的代码--> ...