android错误之android.content.res.Resources$NotFoundException

来源:互联网 发布:淘宝智能版 一钻 编辑:程序博客网 时间:2024/05/17 02:20

今天正好敲完了一个项目的代码,连上手机运行的时候发现报错了:

Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f0c0001

然后看一看报错的具体代码:

@Overridepublic void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {super.onCreateOptionsMenu(menu, inflater);inflater.inflate(R.menu.run_list_options, menu); // 报错}

就是“inflater.inflate(R.menu.run_list_options, menu)”这句报错。大概的意思明白了,找不到资源。

那具体是找不到什么资源呢?一开始也比较费解,后台通过查资料大概弄明白了,就是menu_run_list_options代表的xml文件中引用的资源找不到,于是打开menu/menu_run_list_options.xml 检查一下:

<?xml version="1.0" encoding="utf-8"?><menu xmlns:android="http://schemas.android.com/apk/res/android" >    <item android:id="@+id/menu_item_new_run"          android:showAsAction="always"           android:icon="@android:drawable/"  android:title="@string/new_run"/></menu>

于是乎问题找到了,就在 “android:icon="@android:drawable/” 这句,这里是想要引用一个图标,但句子没写完,只写到了文件夹的层面,所以应该补全:

android:icon="@android:drawable/ic_menu_add"


运行成功,问题解决。


总结:其实这个问题可以概括为一个大类,以后再遇到类似于Resources$NotFound 的问题,可能的解决方法之一就是在引用的xml文件中挨个检查引用资源的句子是否完整与正确。



0 0
原创粉丝点击