2017-02-06 5 views
-5

Я пытаюсь извлечь данные из базы данных Firebase и отображать данные на моей временной шкале с использованием фрагмента. Это отображение не ошибки, но при запуске приложения, он выходит из строяsetAdapter (firebaseRecyclerAdapter) разрушает мою программу

Я пытался комментировать этот бит из [mInterestList.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); 
    } 



} 

} 

Это мой InterestActivity Класс

общественности класс InterestActivity {

Не отображается ошибка, но когда я запускаю приложение, он падает. Я пробовал комментировать этот бит [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)} 
+0

если интерес представляет внутренний класс, сделать его статическое – Linxy

+0

спасибо за вашу помощь, но я попробовал это, и это по-прежнему падает –

+0

вы могли бы просто переместить интерес в свой собственный класс, то – Linxy

ответ

0

После внесения некоторых попыток, вот что я придумал:

1- Сделать классовый интерес в виде отдельного файла. 2- Изменения каждого InterestActivity.Interest в своем классе TimeLineFragment с Interest

и это должны работать

3

Прочитайте сообщение об ошибке

com.google.firebase.database.DatabaseException: Класс com.example.amaobimills.interestmee.InterestActivity $ Интерес отсутствует конструктор без аргументов в. ..

Дайте Interest класс пустой конструктор

public Interest() { 

} 

Кроме того, объявить Interest как static класса в InterestActivity как так

public static class Interest { 
    ... 
+0

У меня есть это в моем интересе Активный общественный класс InterestActivity, но он по-прежнему падает –

+0

Вы только что добавили его? Есть ли еще сообщение об ошибке? –

+0

У меня всегда было это там. –

Смежные вопросы