java.lang.NoClassDefFoundError:android.support.v4.preferencefragment.R $ layout

时间:2014-04-02 14:44:03

标签: java android eclipse android-fragments android-support-library

我有一个扩展android.support.v4.PreferenceFragment的课程。当我运行应用程序时,我首先在LogCat上收到此警告:

04-02 14:22:57.113: W/dalvikvm(28828): VFY: unable to resolve static field 656 (preference_list_fragment) in Landroid/support/v4/preferencefragment/R$layout;

然后点击应用程序用户界面上的选项后,它会关闭并且此错误会出现在LogCat上

04-02 14:22:57.158: E/AndroidRuntime(28828): FATAL EXCEPTION: main
04-02 14:22:57.158: E/AndroidRuntime(28828): java.lang.NoClassDefFoundError: android.support.v4.preferencefragment.R$layout
04-02 14:22:57.158: E/AndroidRuntime(28828):    at android.support.v4.preference.PreferenceFragment.onCreateView(PreferenceFragment.java:95)
04-02 14:22:57.158: E/AndroidRuntime(28828):    at android.support.v4.app.Fragment.performCreateView(Fragment.java:1500)
04-02 14:22:57.158: E/AndroidRuntime(28828):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:927)
04-02 14:22:57.158: E/AndroidRuntime(28828):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
04-02 14:22:57.158: E/AndroidRuntime(28828):    at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
04-02 14:22:57.158: E/AndroidRuntime(28828):    at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1467)
04-02 14:22:57.158: E/AndroidRuntime(28828):    at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:440)
04-02 14:22:57.158: E/AndroidRuntime(28828):    at android.os.Handler.handleCallback(Handler.java:725)
04-02 14:22:57.158: E/AndroidRuntime(28828):    at android.os.Handler.dispatchMessage(Handler.java:92)
04-02 14:22:57.158: E/AndroidRuntime(28828):    at android.os.Looper.loop(Looper.java:137)
04-02 14:22:57.158: E/AndroidRuntime(28828):    at android.app.ActivityThread.main(ActivityThread.java:5039)
04-02 14:22:57.158: E/AndroidRuntime(28828):    at java.lang.reflect.Method.invokeNative(Native Method)
04-02 14:22:57.158: E/AndroidRuntime(28828):    at java.lang.reflect.Method.invoke(Method.java:511)
04-02 14:22:57.158: E/AndroidRuntime(28828):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
04-02 14:22:57.158: E/AndroidRuntime(28828):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
04-02 14:22:57.158: E/AndroidRuntime(28828):    at dalvik.system.NativeStart.main(Native Method)

我已经就同一个问题发了很多帖子,我已经做了以下所有事情:

  • https://github.com/kolavar/android-support-v4-preferencefragment下载PreferenceFragment,将其作为项目导入,并将其作为必需项目添加到我的构建路径中。
  • 使用https://github.com/escrichov/guide/tree/master/android-support-v4-preferencefragment-master以及
  • 的代码尝试了最后一步
  • android-support-v4.jar文件夹中添加了libs,并将其添加到我的构建路径
  • android-support-v4-preferencefragment-master.jar文件夹中添加了libs,并将其添加到我的构建路径
  • 在Java Build Path的Order and Export选项卡中检查了android-support-v4-prerferencefragment
  • 尝试右击我的项目 - > Android工具 - >添加支持库
  • 在每次更改后清理项目
  • 从Android SDK Manager下载Android Support LibraryAndroid Support Repository

但问题仍然存在。

我正在测试nexus 10

1 个答案:

答案 0 :(得分:2)

一般来说,不要手动弄乱构建路径。

您尝试使用的项目是Android库项目。有instructions for adding a dependency on an Android library project to your Eclipse project。鉴于您已将其导入Eclipse工作区,您需要通过项目设置的Android部分将其添加为依赖项:

Android Project Properties

单击“添加”按钮,从对话框中选择此库项目,单击“确定”关闭每个对话框,然后设置。