Java 找不到类“android.support.v4.widget.SwipeRefreshLayout”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23416053/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 22:54:10  来源:igfitidea点击:

Could not find class 'android.support.v4.widget.SwipeRefreshLayout'

javaandroid

提问by Abdul Sadik Yalcin

I keep getting this error and it's causing my app to crash. Trying to implement the new v4 swipe refresh layout. I have updated the support library + sdk. What is the issue?

我不断收到此错误,并导致我的应用程序崩溃。尝试实现新的 v4 滑动刷新布局。我已经更新了支持库 + sdk。问题是什么?

Could not find class 'android.support.v4.widget.SwipeRefreshLayout', referenced from method ......onCreate

找不到类 '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

XML

<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.devrim.ythaber.HomeActivity"
tools:ignore="MergeRootFrame" >

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <ImageView
            android:id="@+id/thumb"
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:contentDescription="@string/app_name" />

        <RelativeLayout
            android:id="@+id/relativeLayout1"
            android:layout_width="wrap_content"
            android:layout_height="290dp"
            android:layout_centerVertical="true"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"
            android:orientation="vertical" >

            <!-- android:layout_toRightOf="@+id/thumb" -->

        </RelativeLayout>

        <TextView
            android:id="@+id/title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="left"
            android:ellipsize="end"
            android:fontFamily="sans-serif-light"
            android:maxLines="2"
            android:shadowColor="@color/dropshadow"
            android:shadowDx="2"
            android:shadowDy="2"
            android:shadowRadius="2"
            android:text="@string/title"
            android:textAllCaps="false"
            android:textAppearance="?android:attr/textAppearanceSmallPopupMenu"
            android:textColor="@color/titlecolour"
            android:textSize="35sp"
            android:textStyle="italic"
            android:typeface="sans" >
        </TextView>

        <TextView
            android:id="@+id/category"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/title"
            android:ellipsize="end"
            android:fontFamily="sans-serif-light"
            android:gravity="right"
            android:maxLines="1"
            android:paddingRight="5dp"
            android:paddingTop="10dp"
            android:textAppearance="?android:attr/textAppearanceSmallPopupMenu"
            android:textColor="@color/catcolour"
            android:textSize="17sp"
            android:textStyle="italic"
            android:typeface="sans" >
        </TextView>
    </LinearLayout>
</ScrollView>
</android.support.v4.widget.SwipeRefreshLayout>

Complete 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;' 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.access0(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)

回答by rwarner

Verify that you're android support library that is installed in your SDK manager is 19.1 and not just 19.

验证您的 SDK 管理器中安装的 android 支持库是否为 19.1 而不仅仅是 19。

If it is and you've tried updating your project to the new library, I've found that, that doesn't work properly. Create a blank new android application project and copy the support library from /libs/ over to your existing project and try it again.

如果是这样,并且您尝试将项目更新到新库,我发现它无法正常工作。创建一个空白的新 android 应用程序项目并将支持库从 /libs/ 复制到您现有的项目,然后再试一次。

回答by Distwo

If you are using graddle, you may want to check that you updated your configuration to use the 19.1 version of the android support library. See following line:

如果您使用的是 graddle,您可能需要检查您是否更新了配置以使用 19.1 版本的 android 支持库。请参阅以下行:

dependencies {
    compile 'com.android.support:support-v4:19.1.+'
}

回答by jenzz

For me, the problem was that one of my library projects was using v13of the support library: android-support-v13.jar.

对我来说,问题是我的一个库项目正在使用支持库的v13android-support-v13.jar.

So look out for a message like this in your logs:

因此,请注意您的日志中是否有这样的消息:

Found both android-support-v4 and android-support-v13 in the dependency list.
Because v13 includes v4, using only v13.

If you see that warning, make sure your library project also includes the latest support library, otherwise your v4library might get superseded by an old v13library (which obviously does not include the new SwipeRefreshLayout).

如果您看到该警告,请确保您的库项目还包含最新的支持库,否则您的v4库可能会被旧的v13库(显然不包括新的SwipeRefreshLayout)取代。