这对我来说是个谜。我不知道如何调试这种情况:
我遇到的问题是在“PreferenceFragment”类中。我开发了一个带有首选项标题的经典“设置”界面:
<preference-headers xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<header
android:fragment="debut.telebox.Config$PrefSystemeFragment"
android:icon="@drawable/ic_action_prefsysteme"
android:title="Paramètres Système"
android:summary="Paramètres système"
/>
<header
android:fragment="debut.telebox.Config$PrefChainesFragment"
android:icon="@drawable/ic_action_preffavoris"
android:title="Paramètres pour les chaînes"
android:summary="Favoris"
/>
<header
android:fragment="debut.telebox.Config$PrefAproposFragment"
android:icon="@drawable/icon"
android:title="A propos"
android:summary="A propos de TeleBox"
/>
PreferenceActivity 是:
public class Config extends PreferenceActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
}
@Override
public void onDestroy() {
super.onDestroy();
...
}
@Override
public void onBuildHeaders(List<Header> target) {
loadHeadersFromResource(R.layout.prefentete, target);
}
public static class PrefSystemeFragment extends PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
当我使用 Eclipse 直接在测试设备(Android 4.0.4 下的 Xoom 和 Nexus S)上运行这个应用程序时,我没有问题:我能够读取和写入参数。
但是当我导出应用程序然后在设备上运行它时,我得到运行时错误:
05-17 17:30:12.680: E/AndroidRuntime(6391): at dalvik.system.NativeStart.main(Native Method)
05-17 17:30:12.680: E/AndroidRuntime(6391): Caused by: android.app.Fragment$InstantiationException: Unable to instantiate fragment debut.telebox.Config$PrefSystemeFragment: make sure class name exists, is public, and has an empty constructor that is public
05-17 17:30:12.680: E/AndroidRuntime(6391): at android.app.Fragment.instantiate(Fragment.java:581)
05-17 17:30:12.680: E/AndroidRuntime(6391): at android.preference.PreferenceActivity.switchToHeaderInner(PreferenceActivity.java:1117)
05-17 17:30:12.680: E/AndroidRuntime(6391): at android.preference.PreferenceActivity.switchToHeader(PreferenceActivity.java:1150)
05-17 17:30:12.680: E/AndroidRuntime(6391): at android.preference.PreferenceActivity.onCreate(PreferenceActivity.java:551)
05-17 17:30:12.680: E/AndroidRuntime(6391): at debut.telebox.Config.onCreate(Unknown Source)
05-17 17:30:12.680: E/AndroidRuntime(6391): at android.app.Activity.performCreate(Activity.java:4465)
05-17 17:30:12.680: E/AndroidRuntime(6391): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
05-17 17:30:12.680: E/AndroidRuntime(6391): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
05-17 17:30:12.680: E/AndroidRuntime(6391): ... 11 more
05-17 17:30:12.680: E/AndroidRuntime(6391): Caused by: java.lang.ClassNotFoundException: debut.telebox.Config$PrefSystemeFragment
05-17 17:30:12.680: E/AndroidRuntime(6391): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
05-17 17:30:12.680: E/AndroidRuntime(6391): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
05-17 17:30:12.680: E/AndroidRuntime(6391): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
05-17 17:30:12.680: E/AndroidRuntime(6391): at android.app.Fragment.instantiate(Fragment.java:571)
05-17 17:30:12.680: E/AndroidRuntime(6391): ... 18 more
05-17 17:30:12.680: W/ActivityManager(161): Force finishing activity debut.telebox/.Config
05-17 17:30:12.690: W/ActivityManager(161): Force finishing activity debut.telebox/.TeleBox
不幸的是,我在 Google Play 上上传了我的应用程序,却没有看到它无法正常工作......