我在java.lang.NoClassDefFoundError上有错误:io.realm.RealmRecyclerViewAdapter $ 1
我正在使用领域compile 'io.realm:android-adapters:2.0.0'
和classpath "io.realm:realm-gradle-plugin:2.2.1"
当我构建我的RealmAdapter时命名为:AdapterJadwalKuliahRV
public class AdapterJadwalKuliahRV extends RealmRecyclerViewAdapter<JadwalKuliahModel, AdapterJadwalKuliahRV.MyViewHolder> {
public AdapterJadwalKuliahRV(OrderedRealmCollection<JadwalKuliahModel> data){
super(data, true);
setHasStableIds(true);
}
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.row_jk, parent, false);
return new MyViewHolder(itemView);
}
@Override
public void onBindViewHolder(MyViewHolder holder, int position){
final JadwalKuliahModel jk = getItem(position);
holder.data= jk;
holder.txtHari.setText(jk.getHari_jk());
holder.txtMakul.setText(jk.getMakul_jk());
holder.txtJam.setText(jk.getWaktu_jk());
holder.txtDosen.setText(jk.getDosen_jk());
holder.txtRuangan.setText(jk.getRuangan_jk());
holder.txtKelas.setText(jk.getKelas_jk());
}
@Override
public int getItemCount(){
return data.size();
}
class MyViewHolder extends RecyclerView.ViewHolder{
private TextView txtHari,txtMakul,txtJam,txtDosen,txtRuangan,txtKelas;
private JadwalKuliahModel data;
private MyViewHolder(View view){
super(view);
txtHari = (TextView) view.findViewById(R.id.rowhariJK);
txtJam = (TextView) view.findViewById(R.id.rowJamjk);
txtMakul = (TextView) view.findViewById(R.id.rowMakul);
txtDosen = (TextView) view.findViewById(R.id.rowDosen);
txtRuangan = (TextView) view.findViewById(R.id.rowRuanganjk);
txtKelas = (TextView) view.findViewById(R.id.rowKelasJK);
}
}
这是ny设置该适配器并实现到我的活动的方法
private void setupRecycler() {
realm.getDefaultInstance();
AdapterJadwalKuliahRV = new AdapterJadwalKuliahRV(realm.where(JadwalKuliahModel.class).findAll());
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setAdapter(AdapterJadwalKuliahRV);
recyclerView.setHasFixedSize(true);
}
这是我的模特
private static AtomicInteger INTEGER_COUNTER = new AtomicInteger(0);
@PrimaryKey
private int no_jk;
private String hari_jk;
private String waktu_jk;
private String makul_jk;
private String ruangan_jk;
private String dosen_jk;
private String kelas_jk, created_at, updated_at;
private String Author;
private int noonline_j;
final static public String jkSort ="";
public JadwalKuliahModel() {
}
public JadwalKuliahModel(int no_jk, String hari_jk, String waktu_jk, String makul_jk, String ruangan_jk, String dosen_jk, String kelas_jk, String created_at, String updated_at, String author, int noonline_j) {
this.no_jk = no_jk;
this.hari_jk = hari_jk;
this.waktu_jk = waktu_jk;
this.ruangan_jk = ruangan_jk;
this.makul_jk = makul_jk;
this.dosen_jk = dosen_jk;
this.kelas_jk = kelas_jk;
this.created_at = created_at;
this.updated_at = updated_at;
this.Author = author;
this.noonline_j = noonline_j;
}
使用Setter和Getter
但是,我有RealmRecyclerViewAdapter的问题 比如this
请帮帮我..
答案 0 :(得分:1)
compile 'io.realm:android-adapters:2.0.0'
仅支持Realm-Java 3.0.0及更高版本(例如当前最新的,classpath "io.realm:realm-gradle-plugin:3.1.2"
)。
要在Realm 2.x中使用realm-android-adapters
,您需要使用compile 'io.realm:android-adapters:1.5.0
。
您收到此异常是因为在Realm 3.0.0之前OrderedRealmCollectionChangeListener
不存在