Firebaseデータベースからデータを取得しようとしていて、フラグメントを使用してタイムラインにデータを表示しようとしています。これは、エラーを表示しませんが、私はアプリケーションを実行すると、それは私が[mInterestList.setAdapter(firebaseRecyclerAdapter);
]このビットをコメントアウトしてみました、それはこれが私のInterestActivityクラスsetAdapter(firebaseRecyclerAdapter)でプログラムがクラッシュする
公開されて
public class TimeLineFragment extends Fragment {
private DatabaseReference mDatabase;
private RecyclerView mInterestList;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
mDatabase = FirebaseDatabase.getInstance().getReference().child("Interest");
View rootView = inflater.inflate(R.layout.fragment_timeline, container, false);
mInterestList = (RecyclerView) rootView.findViewById(R.id.interest_list);
mInterestList.setHasFixedSize(true);
mInterestList.setLayoutManager(new LinearLayoutManager(getActivity()));
return rootView;
}
@Override
public void onStart() {
super.onStart();
FirebaseRecyclerAdapter<InterestActivity.Interest,InterestViewHolder > firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<InterestActivity.Interest, InterestViewHolder>(
InterestActivity.Interest.class,
R.layout.interest_row,
InterestViewHolder.class,
mDatabase
) {
@Override
protected void populateViewHolder(InterestViewHolder viewHolder, InterestActivity.Interest model, int position) {
viewHolder.setTitle(model.getTitle());
viewHolder.setDesc(model.getDescription());
}
};
mInterestList.setAdapter(firebaseRecyclerAdapter);
}
public static class InterestViewHolder extends RecyclerView.ViewHolder {
View mView;
public InterestViewHolder(View itemView) {
super(itemView);
mView = itemView;
}
public void setTitle(String title) {
TextView interest_title = (TextView) mView.findViewById(R.id.Interest_Title);
interest_title.setText(title);
}
public void setDesc(String desc) {
TextView interest_Description = (TextView) mView.findViewById(R.id.interest_Description);
interest_Description.setText(desc);
}
}
}
をクラッシュすることなく働い
をクラッシュclass InterestActivity {
public class Interest {
private String title;
private String description;
private String image;
private String uid;
public Interest(){
}
public Interest(String title, String description, String image, String uid) {
this.title = title;
this.description = description;
this.image = image;
this.uid = uid;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
public String getUid() {
return uid;
}
public void setUid(String uid) {
this.uid = uid;
}
}
}
エラーは表示されませんが、アプリケーションを実行するとクラッシュします。このビットをコメントアウトしようとしましたが[mInterestList.setAdapter(firebaseRecyclerAdapter);
]、クラッシュすることなく動作しました。クラッシュすると、次のエラーメッセージが表示されます。
dRuntime: FATAL EXCEPTION: main
Process: com.example.amaobimills.interestmee, PID: 4350
com.google.firebase.database.DatabaseException: Class com.example.amaobimills.interestmee.InterestActivity$Interest is missing a constructor with no arguments
at com.google.android.gms.internal.zzalq$zza.zze(Unknown Source)
at com.google.android.gms.internal.zzalq$zza.zzcc(Unknown Source)
at com.google.android.gms.internal.zzalq.zzd(Unknown Source)
at com.google.android.gms.internal.zzalq.zzb(Unknown Source)
at com.google.android.gms.internal.zzalq.zza(Unknown Source)
at com.google.firebase.database.DataSnapshot.getValue(Unknown Source)
at com.firebase.ui.database.FirebaseRecyclerAdapter.parseSnapshot(FirebaseRecyclerAdapter.java:147)
at com.firebase.ui.database.FirebaseRecyclerAdapter.getItem(FirebaseRecyclerAdapter.java:136)
at com.firebase.ui.database.FirebaseRecyclerAdapter.onBindViewHolder(FirebaseRecyclerAdapter.java:176)
at android.support.v7.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:6067)
at android.support.v7.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:6100)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5282)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5158)
at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2061)
at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1445)
at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1408)
at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:580)
at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3379)
at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:3188)
at android.support.v7.widget.RecyclerView.consumePendingUpdateOperations(RecyclerView.java:1595)
at android.support.v7.widget.RecyclerView$1.run(RecyclerView.java:323)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
at android.view.Choreographer.doCallbacks(Choreographer.java:580)
at android.view.Choreographer.doFrame(Choreographer.java:549)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
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:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)}
作品の関心は内部クラスであれば、それはあなたの助けのための静的 – Linxy
感謝しますが、私はそれを試してみましたが、それはまだあなただけの可能性 –
がクラッシュすべき2 - 変更 – Linxy