I had this problem because I treated the preference list like a normal activity. It's actually completely different. First, you need to move the XML file from res/layout to res/xml (in Eclipse, you have to create this folder manually). You also have to use different Java code:
import android.os.Bundle;
import android.preference.PreferenceActivity;
public class Settings extends PreferenceActivity { //NOT activity!
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Initialize the preference screen defined in /res/xml/preference.xml
addPreferencesFromResource(R.xml.preferences); //NOT setContentView
}
}
You'll get a warning for API level >=11 about addPreferencesFromResource being deprecated. That's because Android wants you to switch to a preference screen based on fragments ("PreferenceFragments"), which is a fair bit more complicated. There's an example here.
[exec] ..\res\layout\vw_custom_title.xml:22: error: Error: No resource found that matches the given name (at 'background' with value '@drawable/background_title_button_home').
[exec] ..\res\drawable\add_illegal_button.xml:3: error: Error: No resource found that matches the given name (at 'drawable' with value '@drawable/add_illegal_tapped').
[exec] ..\res\drawable\add_illegal_button.xml:6: error: Error: No resource found that matches the given name (at 'drawable' with value '@drawable/add_illegal_tapped').
当使用aapt打包资源文件时发现此问题
因为eclipse的控制台输出量不够,看不到出错的地方的log后再eclipse控制台console 里右键点击出现菜单后选择最后一项 Preferences 里选择调节console buffer size 的大小加个0
[exec] ERROR: 9-patch image D:\workspace\Dili360\res\drawable-hdpi\location_bk.9.png malformed.
[exec] No marked region found along edge.
[exec] Found along top edge.
[exec] ERROR: Failure processing PNG image D:\workspace\Dili360\res\drawable-hdpi\location_bk.9.png
就可以通过以下两种方式来解决问题啦
You might have installed from a separate copy of the code where the version number was higher than the copy you're working with right now. In either case, uninstall the currently installed copy, or open up Settings > Apps to determine the version number for the installed app, and increment your versionCode to be higher in the AndroidManifest.
解决方案二:
This was happening in my project because I was using an XML resource to set the version code.
AndroidManifest.xml:
android:versionCode="@integer/app_version_code"
app.xml:
<integer name="app_version_code">64</integer>
This wasn't a problem in prior versions of adb
, however, as of platform-tools
r16 this is no longer being resolved to the proper integer. You can either force the re-install using adb -r
or avoid the issue entirely by using a literal in the manifest:
- <?xml version="1.0" encoding="utf-8"?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.net.studyplayer.chinese"
- android:versionCode="1"
- android:versionName="1.0" >
- <?xml version="1.0" encoding="utf-8"?>
比如 我们需要把 package="com.net.studyplayer.chinese" 修改成 "com.net.studyplayer.english"
这样 我们就可以在同一台机子上安装这两个APK了 因为他们的包名已经不一样了
但是我们需要修改的地方不只是这一处,还有原文件夹名也要修改
在我们先修改了 AndroidManifest.xml 中的名字之后 会发现文件中凡是有用到R文件的地方都会报错
其实这个就非常简单了
右键点击上图中 "chinese"的那个包
这样子基本上就所有的报错信息都消失了 clean一遍 然后重新编译 就OK了
开始我操作顺序是反的 还要手动改些东西 但是先改 AndroidManifest.xml 然后在执行后面rename的操作就很快