it-swarm.dev

RecyclerView sınıfı şişirilirken hata oluştu

Böylece kodum sadece RecyclerView kullanarak bir CardView listesi oluşturur. Kodumu çalıştırdıktan sonra xml'mde bir hata olduğunu iddia eden garip bir hata alıyorum. Bir süre kontrol ettikten sonra, mizanpaj dosyamda <RecyclerView> __ <Android.support.v7.widget.RecyclerView> ile değiştirirsem her şeyin iyi sonuç vereceğini öğrendim. Bu neden oluyor? 
Faaliyetim.

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);
    }

}


Adaptörüm 

    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);
        }
    }

}


Düzen dosyam, not, <RecyclerView> 'u <Android.support.v7.widget.RecyclerView>' ye değiştirmek hatayı düzeltir. 

<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> ile çalıştırdığımda bu hatayı alıyorum. 

`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.access$800(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.access$800(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.access$800(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

'

28
Liquid Ink

RecyclerView temel Android çerçevesine dahil edilmemiştir, yalnızca temel Android çerçevesindeki widget'lar (ListView, GridView vb gibi) tam ad alanı olmadan düzende belirtilebilir. RecyclerView, recyclerview-v7 destek kütüphanesinin bir parçasıdır.

35
hidro

XML'de RecyclerView'ı şu şekilde eklemelisiniz:

<Android.support.v7.widget.RecyclerView
    Android:layout_width="match_parent"
    Android:layout_height="match_parent"
    Android:id="@+id/cardList">

</Android.support.v7.widget.RecyclerView>

Umarım yardımcı olur!

36
Juancho

Bugün bu problemle karşılaştım .. .. Ve çözdüm.

ilk adım: kullandığınız destek kütüphanelerinin aynı versiyonda kalmaları

compile 'com.Android.support:appcompat-v7:23.1.1'
compile 'com.Android.support:support-v4:23.1.1'
compile 'com.Android.support:recyclerview-v7:23.1.1'

i̇kinci adım: Proguard dosyalarınıza recyclerView eklemelisiniz 

-keep class Android.support.v7.widget.** {*;}
// I`ve just keep all widgets
8
KuRoSan ER.

RecyclerView'ı XML'inize eklemeden önce eklediğinizden emin olun

compile 'com.Android.support:recyclerview-v7:22.2.0'
compile 'com.Android.support:appcompat-v7:22.2.0'

Bu bağımlılıkları eklemeden önce XML'inizde RecyclerView oluşturduysanız, çalışabilmesi için geri dönüşümcü görünümünüzü kaldırmalı (yorum yapmalı), onsuz proje oluşturmalı ve sonra geri eklemelisiniz. Aksi halde, hala #n ikili XML satırında Şişirme istisnasını gösterir.

6
Ivan V
  1. Build.gradle referansını kontrol edin
  2. Xml dosyanızın düzeninde, RecyclerView bileşeninizin adını bir bütün olarak Android.support.v7.widget.RecyclerViewnot like RecyclerView paketiyle yazın

şimdi öğle yemeğine hazırım. İyi yollar

0
fatih