Hello. I try to fill the created RecyclerView with elements, and when I open the activit in which it is located, I get an error. What could it be?

@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_chats); RecyclerView recList = (RecyclerView) findViewById(R.id.cardList); recList.setHasFixedSize(true); LinearLayoutManager llm = new LinearLayoutManager(this); llm.setOrientation(LinearLayoutManager.VERTICAL); recList.setLayoutManager(llm); ContactAdapter ca = new ContactAdapter(createList(30)); recList.setAdapter(ca); } private List<ContactInfo> createList(int size) { List<ContactInfo> result = new ArrayList<ContactInfo>(); for (int i=1; i <= size; i++) { ContactInfo ci = new ContactInfo(); ci.username = "@Moon"; ci.msg = "Hi Luna"; ci.time = "сегодня, 14:21"; result.add(ci); } return result; } 

public class ContactAdapter extends RecyclerView.Adapter {

 private List<ContactInfo> contactList; public ContactAdapter(List<ContactInfo> contactList) { this.contactList = contactList; } @Override public int getItemCount() { return contactList.size(); } @Override public void onBindViewHolder(ContactViewHolder contactViewHolder, int i) { ContactInfo ci = contactList.get(i); contactViewHolder.vUsername.setText(ci.username); contactViewHolder.vMsg.setText(ci.msg); contactViewHolder.vTime.setText(ci.time); } @Override public ContactViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) { View itemView = LayoutInflater. from(viewGroup.getContext()). inflate(R.layout.chats_card_layout, viewGroup, false); return new ContactViewHolder(itemView); } public static class ContactViewHolder extends RecyclerView.ViewHolder { protected TextView vUsername; protected TextView vMsg; protected TextView vTime; public ContactViewHolder(View v) { super(v); vUsername = (TextView) v.findViewById(R.id.chat_username); vMsg = (TextView) v.findViewById(R.id.chat_msg_content); vTime = (TextView) v.findViewById(R.id.chat_time); } } 

}

W / art: Before Android 4.1, method int android.support.v7.widget.ListViewCompat.lookForSelectablePosition (int, boolean) would be correct for android.widget.ListView

  • Add adapter code. - post_zeew

2 answers 2

Apparently a bug in Dalvik interpreter, which allows you to override package-private methods. Google recognized this problem in the Android Jelly Bean version. Here they actually write:

If you’re intending to be a public package, it’s a public package.

In reference to the source.

     for (int i=1; i <= size; i++) { 

    the first element of the array with index 0

     for (int i=0; i < size; i++) { 
    • what does it have to do with it? - lounah
    • The variable i in the cycle is still not used - andreymal