我的活動有一個recyclerview,我的代碼在IDE中沒有錯誤並接受所有支持庫,但是當我嘗試運行我的代碼時,應用程序崩潰。Android中的RecyclerView的NoClassDefFound
是什麼問題?
package com.ed.test4;
import java.util.ArrayList;
import java.util.List;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
private RecyclerView contactsRecyclerView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
contactsRecyclerView = (RecyclerView) findViewById(R.id.contacts_recyclerview);
contactsRecyclerView.setLayoutManager(new LinearLayoutManager(this));
List<Contact> contacts = new ArrayList<>();
for (int i = 0; i < 50; i++) {
contacts.add(new Contact("Contact #" + i));
}
ContactsAdapter adapter = new ContactsAdapter(contacts);
contactsRecyclerView.setAdapter(adapter);
}
private class ContactsAdapter extends RecyclerView.Adapter<ContactHolder> {
private List<Contact> contacts;
public ContactsAdapter(List<Contact> contacts) {
this.contacts = contacts;
}
@Override
public ContactHolder onCreateViewHolder(ViewGroup parent, int viewType) {
LayoutInflater inflater = LayoutInflater.from(MainActivity.this);
View v = inflater.inflate(R.layout.list_item, parent, false);
return new ContactHolder(v);
}
@Override
public void onBindViewHolder(ContactHolder holder, int position) {
Contact contact = contacts.get(position);
holder.tvContactName.setText(contact.getName());
holder.tvContactRegisterDate.setText(contact.getRegisterDate().toString());
}
@Override
public int getItemCount() {
return contacts.size();
}
}
private class ContactHolder extends RecyclerView.ViewHolder {
private TextView tvContactName, tvContactRegisterDate;
public ContactHolder(View itemView) {
super(itemView);
tvContactName = (TextView) itemView.findViewById(R.id.contact_name_textview);
tvContactRegisterDate = (TextView) itemView.findViewById(R.id.contact_register_date_textview);
}
}
public class Contact {
private String name;
private Date registerDate;
public Contact(String name) {
this.name = name;
registerDate = new Date();
}
public String getName() {
return name;
}
public Date getRegisterDate() {
return registerDate;
}
public void setName(String name) {
this.name = name;
}
}
}
and this is screenshot of logcat shows error
請分享Manifest&XML文件 – Ajinkya
請參閱此鏈接。它可以幫助你http://stackoverflow.com/questions/31672233/recyclerview-class-android-support-v7-recyclerview-rstyleable-can-not-be-found,這也太http://stackoverflow.com/questions/ 20900832/java-lang-noclassdeffounderror-android-support-v7-appcompat-rstyleable – ajantha