android– 错误膨胀类RecyclerView

android– 错误膨胀类RecyclerView,第1张

概述所以我的代码只使用RecyclerView创建了一个CardView列表.运行我的代码后,我一直收到一个奇怪的错误,声称我的xml中有错误.经过修补一段时间后,我发现在我的布局文件中,如果我更改<RecyclerView>to<android.support.v7.widget.RecyclerView>一切都会好起来的.为什么会这样?我的活

所以我的代码只使用RecyclerVIEw创建了一个CardVIEw列表.运行我的代码后,我一直收到一个奇怪的错误,声称我的xml中有错误.经过修补一段时间后,我发现在我的布局文件中,如果我更改< RecyclerVIEw> to< android.support.v7.Widget.RecyclerVIEw>一切都会好起来的.为什么会这样?我的活动.

import androID.support.v7.app.ActionBaractivity;import androID.os.Bundle;import androID.support.v7.Widget.linearlayoutmanager;import androID.support.v7.Widget.RecyclerVIEw;import androID.vIEw.Menu;import androID.vIEw.MenuItem;import java.util.ArrayList;public class CardListActivity extends ActionBaractivity {    @OverrIDe    protected voID onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentVIEw(R.layout.activity_card_List);        RecyclerVIEw recyclerVIEw = (RecyclerVIEw)findVIEwByID(R.ID.cardList);        recyclerVIEw.setHasFixedSize(true);        linearlayoutmanager linearlayoutmanager = new linearlayoutmanager(this);        linearlayoutmanager.setorIEntation(linearlayoutmanager.VERTICAL);        recyclerVIEw.setLayoutManager(linearlayoutmanager);        ArrayList<String> List = new ArrayList<>();        for(int i = 0; i < 20; i++) {List.add("Item " + i);}        Cardlistadapter cardlistadapter = new Cardlistadapter(List);        recyclerVIEw.setAdapter(cardlistadapter);    }}

我的适配器

    import androID.support.v7.Widget.RecyclerVIEw;import androID.vIEw.LayoutInflater;import androID.vIEw.VIEw;import androID.vIEw.VIEwGroup;import androID.Widget.TextVIEw;import java.util.List;public class Cardlistadapter extends RecyclerVIEw.Adapter<Cardlistadapter.CardListVIEwHolder> {    private List<String> List;    public Cardlistadapter(List<String> List) {        this.List = List;    }    @OverrIDe    public CardListVIEwHolder onCreateVIEwHolder(VIEwGroup vIEwGroup, int i) {        VIEw v = LayoutInflater.from(vIEwGroup.getContext()).inflate(R.layout.card_layout,vIEwGroup,false);        return new CardListVIEwHolder(v);    }    @OverrIDe    public voID onBindVIEwHolder(CardListVIEwHolder cardListVIEwHolder, int i) {        String s = List.get(i);        cardListVIEwHolder.Title.setText(s);    }    @OverrIDe    public int getItemCount() {        return List.size();    }    public static class CardListVIEwHolder extends RecyclerVIEw.VIEwHolder {        TextVIEw Title;        public CardListVIEwHolder(VIEw itemVIEw) {            super(itemVIEw);            Title = (TextVIEw)itemVIEw.findVIEwByID(R.ID.Title);        }    }}

 我的布局文件,注意,更改< RecyclerVIEw> to< androID.support.v7.Widget.RecyclerVIEw>修复错误.

<relativeLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"xmlns:tools="http://schemas.androID.com/tools" androID:layout_wIDth="match_parent"androID:layout_height="match_parent" androID:paddingleft="@dimen/activity_horizontal_margin"androID:paddingRight="@dimen/activity_horizontal_margin"androID:paddingtop="@dimen/activity_vertical_margin"androID:paddingBottom="@dimen/activity_vertical_margin" tools:context=".CardListActivity"><RecyclerVIEw    androID:layout_wIDth="match_parent"    androID:layout_height="match_parent"    androID:ID="@+ID/cardList">    </RecyclerVIEw>

当我使用< RecyclerVIEw>运行时我得到这个错误,.

`Process: com.liquIDink.lollipopmaterialui, PID: 7317    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.liquIDink.lollipopmaterialui/com.liquIDink.lollipopmaterialui.CardListActivity}: androID.vIEw.InflateException: Binary XML file line #8: Error inflating class RecyclerVIEw            at androID.app.ActivityThread.performlaunchActivity(ActivityThread.java:2298)            at androID.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)            at androID.app.ActivityThread.access0(ActivityThread.java:144)            at androID.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)            at androID.os.Handler.dispatchMessage(Handler.java:102)            at androID.os.Looper.loop(Looper.java:135)            at androID.app.ActivityThread.main(ActivityThread.java:5221)            at java.lang.reflect.Method.invoke(Native Method)            at java.lang.reflect.Method.invoke(Method.java:372)            at com.androID.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)            at com.androID.internal.os.ZygoteInit.main(ZygoteInit.java:694)     Caused by: androID.vIEw.InflateException: Binary XML file line #8: Error inflating class RecyclerVIEw            at androID.vIEw.LayoutInflater.createVIEwFromTag(LayoutInflater.java:757)            at androID.vIEw.LayoutInflater.rInflate(LayoutInflater.java:806)            at androID.vIEw.LayoutInflater.inflate(LayoutInflater.java:504)            at androID.vIEw.LayoutInflater.inflate(LayoutInflater.java:414)            at androID.vIEw.LayoutInflater.inflate(LayoutInflater.java:365)            at androID.support.v7.app.ActionBaractivityDelegateBase.setContentVIEw(ActionBaractivityDelegateBase.java:228)            at androID.support.v7.app.ActionBaractivity.setContentVIEw(ActionBaractivity.java:102)            at com.liquIDink.lollipopmaterialui.CardListActivity.onCreate(CardListActivity.java:18)            at androID.app.Activity.performCreate(Activity.java:5933)            at androID.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)            at androID.app.ActivityThread.performlaunchActivity(ActivityThread.java:2251)            at androID.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)            at androID.app.ActivityThread.access0(ActivityThread.java:144)            at androID.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)            at androID.os.Handler.dispatchMessage(Handler.java:102)            at androID.os.Looper.loop(Looper.java:135)            at androID.app.ActivityThread.main(ActivityThread.java:5221)            at java.lang.reflect.Method.invoke(Native Method)            at java.lang.reflect.Method.invoke(Method.java:372)            at com.androID.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)            at com.androID.internal.os.ZygoteInit.main(ZygoteInit.java:694)     Caused by: java.lang.classNotFoundException: DIDn't find class "androID.vIEw.RecyclerVIEw" on path: DexPathList[[zip file "/data/app/com.liquIDink.lollipopmaterialui-2/base.apk"],nativelibraryDirectorIEs=[/vendor/lib, /system/lib]]            at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)            at java.lang.classLoader.loadClass(ClassLoader.java:511)            at java.lang.classLoader.loadClass(ClassLoader.java:469)            at androID.vIEw.LayoutInflater.createVIEw(LayoutInflater.java:571)            at androID.vIEw.LayoutInflater.onCreateVIEw(LayoutInflater.java:665)            at com.androID.internal.policy.impl.PhoneLayoutInflater.onCreateVIEw(PhoneLayoutInflater.java:65)            at androID.vIEw.LayoutInflater.onCreateVIEw(LayoutInflater.java:682)            at androID.vIEw.LayoutInflater.createVIEwFromTag(LayoutInflater.java:741)            at androID.vIEw.LayoutInflater.rInflate(LayoutInflater.java:806)            at androID.vIEw.LayoutInflater.inflate(LayoutInflater.java:504)            at androID.vIEw.LayoutInflater.inflate(LayoutInflater.java:414)            at androID.vIEw.LayoutInflater.inflate(LayoutInflater.java:365)            at androID.support.v7.app.ActionBaractivityDelegateBase.setContentVIEw(ActionBaractivityDelegateBase.java:228)            at androID.support.v7.app.ActionBaractivity.setContentVIEw(ActionBaractivity.java:102)            at com.liquIDink.lollipopmaterialui.CardListActivity.onCreate(CardListActivity.java:18)            at androID.app.Activity.performCreate(Activity.java:5933)            at androID.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)            at androID.app.ActivityThread.performlaunchActivity(ActivityThread.java:2251)            at androID.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)            at androID.app.ActivityThread.access0(ActivityThread.java:144)            at androID.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)            at androID.os.Handler.dispatchMessage(Handler.java:102)            at androID.os.Looper.loop(Looper.java:135)            at androID.app.ActivityThread.main(ActivityThread.java:5221)            at java.lang.reflect.Method.invoke(Native Method)            at java.lang.reflect.Method.invoke(Method.java:372)            at com.androID.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)            at com.androID.internal.os.ZygoteInit.main(ZygoteInit.java:694)    Suppressed: java.lang.classNotFoundException: androID.vIEw.RecyclerVIEw            at java.lang.class.classForname(Native Method)            at java.lang.BootClassLoader.findClass(ClassLoader.java:781)            at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)            at java.lang.classLoader.loadClass(ClassLoader.java:504)            ... 26 more     Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available

`

解决方法:

RecyclerVIEw不包含在基础AndroID框架中,只有基本AndroID框架中的小部件(如ListVIEw,GrIDVIEw等)可以在没有完整命名空间的布局中指定. RecyclerVIEw是recyclerview-v7支持库的一部分.

总结

以上是内存溢出为你收集整理的android – 错误膨胀类RecyclerView全部内容,希望文章能够帮你解决android – 错误膨胀类RecyclerView所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1100138.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存