找不到类’android.support.v4.widget.SwipeRefreshLayout’
我一直收到这个错误,这导致我的应用程序崩溃。 尝试实现新的v4滑动刷新布局。 我更新了支持库+ sdk。 有什么问题?
找不到类’android.support.v4.widget.SwipeRefreshLayout’,引自方法…… onCreate
import android.support.v4.widget.SwipeRefreshLayout; ... private SwipeRefreshLayout swipeLayout; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.home_page_list); swipeLayout = (SwipeRefreshLayout) findViewById(R.id.container); swipeLayout.setColorScheme(android.R.color.holo_blue_bright, android.R.color.holo_green_light, android.R.color.holo_orange_light, android.R.color.holo_red_light); swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { swipeLayout.setRefreshing(false); } });
XML
完整的logcat:
05-01 21:31:27.390: W/dalvikvm(11452): VFY: unable to find class referenced in signature (Landroid/support/v4/widget/SwipeRefreshLayout;) 05-01 21:31:27.390: E/dalvikvm(11452): Could not find class 'android.support.v4.widget.SwipeRefreshLayout', referenced from method com.devrim.ythaber.HomeActivity.onCreate 05-01 21:31:27.390: W/dalvikvm(11452): VFY: unable to resolve check-cast 619 (Landroid/support/v4/widget/SwipeRefreshLayout;) in Lcom/devrim/ythaber/HomeActivity; 05-01 21:31:27.390: W/dalvikvm(11452): Link of class 'Lcom/devrim/ythaber/HomeActivity$1;' failed 05-01 21:31:27.440: W/dalvikvm(11452): threadid=1: thread exiting with uncaught exception (group=0x4166ee18) 05-01 21:31:27.440: E/AndroidRuntime(11452): FATAL EXCEPTION: main 05-01 21:31:27.440: E/AndroidRuntime(11452): Process: com.devrim.ythaber, PID: 11452 05-01 21:31:27.440: E/AndroidRuntime(11452): java.lang.NoClassDefFoundError: android.support.v4.widget.SwipeRefreshLayout 05-01 21:31:27.440: E/AndroidRuntime(11452): at com.devrim.ythaber.HomeActivity.onCreate(HomeActivity.java:56) 05-01 21:31:27.440: E/AndroidRuntime(11452): at android.app.Activity.performCreate(Activity.java:5312) 05-01 21:31:27.440: E/AndroidRuntime(11452): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1111) 05-01 21:31:27.440: E/AndroidRuntime(11452): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2552) 05-01 21:31:27.440: E/AndroidRuntime(11452): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2653) 05-01 21:31:27.440: E/AndroidRuntime(11452): at android.app.ActivityThread.access$800(ActivityThread.java:156) 05-01 21:31:27.440: E/AndroidRuntime(11452): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1355) 05-01 21:31:27.440: E/AndroidRuntime(11452): at android.os.Handler.dispatchMessage(Handler.java:102) 05-01 21:31:27.440: E/AndroidRuntime(11452): at android.os.Looper.loop(Looper.java:157) 05-01 21:31:27.440: E/AndroidRuntime(11452): at android.app.ActivityThread.main(ActivityThread.java:5872) 05-01 21:31:27.440: E/AndroidRuntime(11452): at java.lang.reflect.Method.invokeNative(Native Method) 05-01 21:31:27.440: E/AndroidRuntime(11452): at java.lang.reflect.Method.invoke(Method.java:515) 05-01 21:31:27.440: E/AndroidRuntime(11452): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1069) 05-01 21:31:27.440: E/AndroidRuntime(11452): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:885)
如果您使用的是graddle,您可能需要检查是否更新了配置以使用19.1版本的android支持库。 见以下行:
dependencies { compile 'com.android.support:support-v4:19.1.+' }
对我来说,问题是我的一个库项目使用了支持库的v13 : android-support-v13.jar
。
因此,请在日志中注意这样的消息:
Found both android-support-v4 and android-support-v13 in the dependency list. Because v13 includes v4, using only v13.
如果您看到该警告,请确保您的库项目还包含最新的支持库,否则您的v4库可能会被旧的v13库(显然不包括新的SwipeRefreshLayout
) SwipeRefreshLayout
。
确认您的SDK管理器中安装的Android支持库是19.1而不仅仅是19。
如果是,并且您已尝试将项目更新到新库,我发现,这不能正常工作。 创建一个空白的新Android应用程序项目,并将支持库从/ libs / over复制到现有项目并再次尝试。