Vemuri Pavan
Vemuri Pavan

Reputation: 505

Firebase to RecyclerView: No adapter attached; skipping layout

I have searched for this error in stack overflow and tried all the methods but i can get the solution and here is what I did:

I tried to retrieve data from Firebase database where each node contains name,id,and image source link, and tried to load the data in the recycler view in a fragment
here is my fragment

public class CAKE extends Fragment {
private RecyclerView recyclerview;
private  ListViewAdaptor adaptor;
ArrayList<Data> info;

DatabaseReference mref;
public CAKE() {
    // Required empty public constructor
}


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



    info = new ArrayList<>();
    mref = FirebaseDatabase.getInstance().getReference("Cakes");

    mref.addChildEventListener(new ChildEventListener() {
        @Override
        public void onChildAdded(DataSnapshot dataSnapshot, String s) {
            Data a = dataSnapshot.getValue(Data.class);
            Log.v("data","added");
            info.add(a);
            adaptor = new ListViewAdaptor(getActivity(),info);
            recyclerview.setLayoutManager(new 
            LinearLayoutManager(getActivity()));
            recyclerview.hasFixedSize();
            recyclerview.setAdapter(adaptor);
        }

        @Override
        public void onChildChanged(DataSnapshot dataSnapshot, String s) {

        }

        @Override
        public void onChildRemoved(DataSnapshot dataSnapshot) {

        }

        @Override
        public void onChildMoved(DataSnapshot dataSnapshot, String s) {

        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });








     return  view;
    }

}

and my i received data to my data class:

    public class Data {
   private String id,name,img;
   public Data(){

   }

    public Data(String id, String name, String img) {
        this.id = id;
        this.name = name;
        this.img = img;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getImg() {
        return img;
    }

    public void setImg(String img) {
        this.img = img;
    }
}

and here is my adapter class for the recycler view:

    public class ListViewAdaptor extends RecyclerView.Adapter 
    <ListViewAdaptor.MyViewHolder>{
    private LayoutInflater inflater;


    ArrayList<Data> info;




    public ListViewAdaptor(Context context, ArrayList<Data> info){
        inflater = LayoutInflater.from(context);
        this.info = info;
       // Log.v("test",info.get(2).getName());

    }
    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.list_item,parent,false);
        MyViewHolder holder = new MyViewHolder(view);
        return holder;



    }


    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {


        holder.text.setText(info.get(position).getId());
        holder.text2.setText(info.get(position).getName());
        holder.img.setImageResource(R.drawable.itachi);

    }

    @Override
    public int getItemCount() {
        return info.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        TextView text,text2;
        ImageView img;

        public MyViewHolder(View itemView) {
            super(itemView);
            text = (TextView) itemView.findViewById(R.id.itemtext1);
            text2 = (TextView) itemView.findViewById(R.id.itemtext2);
            img = (ImageView) itemView.findViewById(R.id.itemimage);
        }
    }
}

and note that i set the image in the adapter class from local(drawable) and ignored the image link from the database

my logcat :

    01-22 10:35:50.904 32317-32317/com.example.itachi.com.pab E/RecyclerView: No adapter attached; skipping layout
01-22 10:35:50.904 32317-32317/com.example.itachi.com.pab E/RecyclerView: No adapter attached; skipping layout
01-22 10:35:50.958 32317-32343/com.example.itachi.com.pab D/NetworkSecurityConfig: No Network Security Config specified, using platform default
01-22 10:35:50.996 32317-32317/com.example.itachi.com.pab W/art: Before Android 4.1, method int android.support.v7.widget.ListViewCompat.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView
01-22 10:35:51.037 32317-32336/com.example.itachi.com.pab D/FA: Connected to remote service
01-22 10:35:51.038 32317-32336/com.example.itachi.com.pab V/FA: Processing queued up service tasks: 4
01-22 10:35:53.744 32317-32317/com.example.itachi.com.pab W/ClassMapper: No setter/field for ID found on class com.example.itachi.com.pab.Data (fields/setters are case sensitive!)
01-22 10:35:53.745 32317-32317/com.example.itachi.com.pab W/ClassMapper: No setter/field for image found on class com.example.itachi.com.pab.Data
01-22 10:35:53.745 32317-32317/com.example.itachi.com.pab W/ClassMapper: No setter/field for Name found on class com.example.itachi.com.pab.Data (fields/setters are case sensitive!)
01-22 10:35:53.745 32317-32317/com.example.itachi.com.pab V/data: added
01-22 10:35:53.750 32317-32317/com.example.itachi.com.pab W/ClassMapper: No setter/field for ID found on class com.example.itachi.com.pab.Data (fields/setters are case sensitive!)
01-22 10:35:53.750 32317-32317/com.example.itachi.com.pab W/ClassMapper: No setter/field for image found on class com.example.itachi.com.pab.Data
01-22 10:35:53.750 32317-32317/com.example.itachi.com.pab W/ClassMapper: No setter/field for Name found on class com.example.itachi.com.pab.Data (fields/setters are case sensitive!)
01-22 10:35:53.750 32317-32317/com.example.itachi.com.pab V/data: added
01-22 10:35:53.752 32317-32317/com.example.itachi.com.pab W/ClassMapper: No setter/field for ID found on class com.example.itachi.com.pab.Data (fields/setters are case sensitive!)
01-22 10:35:53.752 32317-32317/com.example.itachi.com.pab W/ClassMapper: No setter/field for image found on class com.example.itachi.com.pab.Data
01-22 10:35:53.752 32317-32317/com.example.itachi.com.pab W/ClassMapper: No setter/field for Name found on class com.example.itachi.com.pab.Data (fields/setters are case sensitive!)
01-22 10:35:53.752 32317-32317/com.example.itachi.com.pab V/data: added
01-22 10:35:53.753 32317-32317/com.example.itachi.com.pab W/ClassMapper: No setter/field for ID found on class com.example.itachi.com.pab.Data (fields/setters are case sensitive!)
01-22 10:35:53.753 32317-32317/com.example.itachi.com.pab W/ClassMapper: No setter/field for image found on class com.example.itachi.com.pab.Data
01-22 10:35:53.754 32317-32317/com.example.itachi.com.pab W/ClassMapper: No setter/field for Name found on class com.example.itachi.com.pab.Data (fields/setters are case sensitive!)
01-22 10:35:53.754 32317-32317/com.example.itachi.com.pab V/data: added
01-22 10:35:53.755 32317-32317/com.example.itachi.com.pab W/ClassMapper: No setter/field for ID found on class com.example.itachi.com.pab.Data (fields/setters are case sensitive!)
01-22 10:35:53.755 32317-32317/com.example.itachi.com.pab W/ClassMapper: No setter/field for image found on class com.example.itachi.com.pab.Data
01-22 10:35:53.755 32317-32317/com.example.itachi.com.pab W/ClassMapper: No setter/field for Name found on class com.example.itachi.com.pab.Data (fields/setters are case sensitive!)
01-22 10:35:53.755 32317-32317/com.example.itachi.com.pab V/data: added
01-22 10:35:53.756 32317-32317/com.example.itachi.com.pab W/ClassMapper: No setter/field for ID found on class com.example.itachi.com.pab.Data (fields/setters are case sensitive!)
01-22 10:35:53.756 32317-32317/com.example.itachi.com.pab W/ClassMapper: No setter/field for image found on class com.example.itachi.com.pab.Data
01-22 10:35:53.757 32317-32317/com.example.itachi.com.pab W/ClassMapper: No setter/field for Name found on class com.example.itachi.com.pab.Data (fields/setters are case sensitive!)
01-22 10:35:53.757 32317-32317/com.example.itachi.com.pab V/data: added
01-22 10:35:53.758 32317-32317/com.example.itachi.com.pab W/ClassMapper: No setter/field for ID found on class com.example.itachi.com.pab.Data (fields/setters are case sensitive!)
01-22 10:35:53.758 32317-32317/com.example.itachi.com.pab W/ClassMapper: No setter/field for image found on class com.example.itachi.com.pab.Data
01-22 10:35:53.758 32317-32317/com.example.itachi.com.pab W/ClassMapper: No setter/field for Name found on class com.example.itachi.com.pab.Data (fields/setters are case sensitive!)
01-22 10:35:53.758 32317-32317/com.example.itachi.com.pab V/data: added
01-22 10:35:53.759 32317-32317/com.example.itachi.com.pab W/ClassMapper: No setter/field for ID found on class com.example.itachi.com.pab.Data (fields/setters are case sensitive!)
01-22 10:35:53.759 32317-32317/com.example.itachi.com.pab W/ClassMapper: No setter/field for image found on class com.example.itachi.com.pab.Data
01-22 10:35:53.759 32317-32317/com.example.itachi.com.pab W/ClassMapper: No setter/field for Name found on class com.example.itachi.com.pab.Data (fields/setters are case sensitive!)
01-22 10:35:53.759 32317-32317/com.example.itachi.com.pab V/data: added
01-22 10:35:53.760 32317-32317/com.example.itachi.com.pab W/ClassMapper: No setter/field for ID found on class com.example.itachi.com.pab.Data (fields/setters are case sensitive!)
01-22 10:35:53.760 32317-32317/com.example.itachi.com.pab W/ClassMapper: No setter/field for image found on class com.example.itachi.com.pab.Data
01-22 10:35:53.760 32317-32317/com.example.itachi.com.pab W/ClassMapper: No setter/field for Name found on class com.example.itachi.com.pab.Data (fields/setters are case sensitive!)
01-22 10:35:53.760 32317-32317/com.example.itachi.com.pab V/data: added
01-22 10:35:53.761 32317-32317/com.example.itachi.com.pab W/ClassMapper: No setter/field for ID found on class com.example.itachi.com.pab.Data (fields/setters are case sensitive!)
01-22 10:35:53.761 32317-32317/com.example.itachi.com.pab W/ClassMapper: No setter/field for image found on class com.example.itachi.com.pab.Data
01-22 10:35:53.761 32317-32317/com.example.itachi.com.pab W/ClassMapper: No setter/field for Name found on class com.example.itachi.com.pab.Data (fields/setters are case sensitive!)
01-22 10:35:53.761 32317-32317/com.example.itachi.com.pab V/data: added
01-22 10:35:53.762 32317-32317/com.example.itachi.com.pab W/ClassMapper: No setter/field for ID found on class com.example.itachi.com.pab.Data (fields/setters are case sensitive!)
01-22 10:35:53.762 32317-32317/com.example.itachi.com.pab W/ClassMapper: No setter/field for image found on class com.example.itachi.com.pab.Data
01-22 10:35:53.762 32317-32317/com.example.itachi.com.pab W/ClassMapper: No setter/field for Name found on class com.example.itachi.com.pab.Data (fields/setters are case sensitive!)
01-22 10:35:53.762 32317-32317/com.example.itachi.com.pab V/data: added
01-22 10:35:53.763 32317-32317/com.example.itachi.com.pab W/ClassMapper: No setter/field for ID found on class com.example.itachi.com.pab.Data (fields/setters are case sensitive!)
01-22 10:35:53.763 32317-32317/com.example.itachi.com.pab W/ClassMapper: No setter/field for image found on class com.example.itachi.com.pab.Data
01-22 10:35:53.763 32317-32317/com.example.itachi.com.pab W/ClassMapper: No setter/field for Name found on class com.example.itachi.com.pab.Data (fields/setters are case sensitive!)
01-22 10:35:53.763 32317-32317/com.example.itachi.com.pab V/data: added
01-22 10:35:53.764 32317-32317/com.example.itachi.com.pab W/ClassMapper: No setter/field for ID found on class com.example.itachi.com.pab.Data (fields/setters are case sensitive!)
01-22 10:35:53.764 32317-32317/com.example.itachi.com.pab W/ClassMapper: No setter/field for image found on class com.example.itachi.com.pab.Data
01-22 10:35:53.764 32317-32317/com.example.itachi.com.pab W/ClassMapper: No setter/field for Name found on class com.example.itachi.com.pab.Data (fields/setters are case sensitive!)
01-22 10:35:53.764 32317-32317/com.example.itachi.com.pab V/data: added
01-22 10:35:56.218 32317-32336/com.example.itachi.com.pab V/FA: Inactivity, disconnecting from the service
01-22 10:36:28.963 32317-32390/com.example.itachi.com.pab V/FA: Recording user engagement, ms: 38264
01-22 10:36:28.966 32317-32390/com.example.itachi.com.pab V/FA: Using measurement service
01-22 10:36:28.967 32317-32390/com.example.itachi.com.pab V/FA: Connecting to remote service
01-22 10:36:28.978 32317-32390/com.example.itachi.com.pab V/FA: Activity paused, time: 160621435
01-22 10:36:28.984 32317-32390/com.example.itachi.com.pab D/FA: Logging event (FE): user_engagement(_e), Bundle[{firebase_event_origin(_o)=auto, engagement_time_msec(_et)=38264, firebase_screen_class(_sc)=Home, firebase_screen_id(_si)=-8384109223359833648}]
01-22 10:36:29.100 32317-32390/com.example.itachi.com.pab V/FA: Using measurement service
01-22 10:36:29.101 32317-32390/com.example.itachi.com.pab V/FA: Connection attempt already in progress
01-22 10:36:29.101 32317-32390/com.example.itachi.com.pab D/FA: Connected to remote service
01-22 10:36:29.101 32317-32390/com.example.itachi.com.pab V/FA: Processing queued up service tasks: 2
01-22 10:36:34.128 32317-32390/com.example.itachi.com.pab V/FA: Inactivity, disconnecting from the service
01-22 10:36:34.295 32317-32322/com.example.itachi.com.pab I/art: Do partial code cache collection, code=16KB, data=31KB
01-22 10:36:34.295 32317-32322/com.example.itachi.com.pab I/art: After code cache collection, code=11KB, data=28KB
01-22 10:36:34.295 32317-32322/com.example.itachi.com.pab I/art: Increasing code cache capacity to 128KB

im unable to see the terxtview in the app

Upvotes: 0

Views: 720

Answers (1)

Burhanuddin Rashid
Burhanuddin Rashid

Reputation: 5370

You are not able to see the text because your data/model class variable name is different than the key name store on firebase database

In logcat its showing this

No setter/field for ID found on class com.example.itachi.com.pab.Data (fields/setters are case sensitive!)
No setter/field for image found on class com.example.itachi.com.pab.Data
No setter/field for Name found on class com.example.itachi.com.pab.Data (fields/setters are case sensitive!)

Which cleary says that you should change the variable name in data class to match exact in your firebase database like this

public class Data {

   // your varibale name is changed to match the firebase db

   private String ID,Name,image;

   public Data(){

   }

    public Data(String id, String name, String img) {
        this.ID= id;
        this.Name= name;
        this.image= img;
    }

    public String getId() {
        return ID;
    }

    public void setId(String id) {
        this.ID= id;
    }

    public String getName() {
        return Name;
    }

    public void setName(String name) {
        this.Name = name;
    }

    public String getImg() {
        return image;
    }

    public void setImg(String img) {
        this.image= img;
    }
}

Upvotes: 1

Related Questions