Android错误膨胀类SwipeRefreshLayout

标签 android android-fragments swiperefreshlayout

我现在正在开发一个应用程序,它使用 3 个选项卡,每个选项卡都有一个 fragment ,我正在尝试在每个 fragment 中实现 SwipeRefreshLayout。我相信我已经正确地创建了这个,但我继续收到错误:

android.view.InflateException: Binary XML file line #1: Error inflating class SwipeRefreshLayout
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.SwipeRefreshLayout" on path: DexPathList[[zip file "/data/app/com.ryan.brooks.fropllc.frop.app-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.ryan.brooks.fropllc.frop.app-1, /vendor/lib, /system/lib]]
    at com.ryan.brooks.fropllc.frop.app.whatsGoingOnFragment.onCreateView(whatsGoingOnFragment.java:23)

现在我完全不知道是什么原因造成的。如果有人可以帮助我,将不胜感激。

这是我实现 SwipeRefreshLayout 的 fragment 布局:

<SwipeRefreshLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/swipe_refresh_whats_going_on">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#343434"></ScrollView>

</SwipeRefreshLayout>

这是我调用 SwipeRefreshLayout 的 fragment 类。

public class WhatsGoingOnFragment extends Fragment {

    private SwipeRefreshLayout swipeLayout;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.whats_going_on_fragment, container, false);

        // Retrieve the SwipeRefreshLayout and ListView instances
        swipeLayout = (SwipeRefreshLayout) view.findViewById(R.id.swipe_refresh_whats_going_on);

        // Set the color scheme of the SwipeRefreshLayout by providing 4 color resource ids
        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);

        return view;
    }
}

所有 3 个 fragment 的布局和类结构都完全相同,只是 id 名称发生了变化。我真的不知道这里出了什么问题。再次感谢任何帮助!

最佳答案

SwipeRefreshLayout需要使用完整的包名:

<android.support.v4.widget.SwipeRefreshLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.ryan.brooks.fropllc.frop.app.whatsGoingOnFragment"
    android:id="@+id/swipe_refresh_whats_going_on">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#343434"></ScrollView>

</android.support.v4.widget.SwipeRefreshLayout>

关于Android错误膨胀类SwipeRefreshLayout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24029304/

相关文章:

android - 如何使用带有下拉刷新和滑动删除的Listview

android - 使用emptyView和ListView时的SwipeRefreshLayout问题

Android SwipeRefreshLayout如果child不是ListView或ScrollView如何实现canChildScrollUp

android - fragment 中自定义布局中的 ZXing 条码扫描器

android - 我可以在 DrawerLayout 中使用 SwipeRefreshLayout 吗?

android - 在 android 中替换 fragment 时 addToBackstack 不起作用

java - Android 线程上的 fragment 替换(...)

android - 永久保存我的应用程序设置

android - 与 Tomcat servlet 交互的类

java - Android:实现了 HeaderListView,无法访问 RowItem