一个android HelloWorld工程在运行的过程中出现Error executing aapt: Return code -1073741819错误
出现错误后我重新新建一个工程 ,照样还是不行,运行后照样出现此类错误,后来意识到是不是我不该修改掉String.xml中的内容导致的错误
当初String.xml中自带有下列标签:
<string name="app_name">Core</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string>
被我修改后只有:
<string name="app_name">Core</string>
。。。以及自己的几百条string项。我修改String.xml中的内容保存时就会报错。后台打印的错误信息中显示aapt相关错误。
此时在R中也找不到自动生成的我自己添加的标签元素的相关类。
我又重新把后面两句
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string>
放进来。再修改保存不会出现任何错误。在资源文件中增加的标签元素也在R中自动生成了相应的类。
可以删掉
<string name="hello_world">Hello world!</string>
保留
<string name="action_settings">Settings</string>
此后程序运行正常。
然后查找 <string name="action_settings">Settings</string>
的使用位置,发现在menu/main.xml里面
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:showAsAction="never"
android:title="@string/action_settings"/>
</menu>
aapt是专门用来对付资源的,如果它报错肯定是资源问题。