0

I am working on an Android app. I use Firebase database. But I am stuck with a problem. My app crashes when I use FirebaseUI RecyclerViewAdapter. Here are all my dependencies:

compile 'com.google.firebase:firebase-auth:11.0.1'
compile 'com.google.firebase:firebase-database:11.0.1'
compile 'com.google.firebase:firebase-storage:11.0.1'
compile 'com.firebaseui:firebase-ui-database:2.0.1' 
 // For Phone number Auth
compile 'com.google.android.gms:play-services-auth:11.0.1'
compile 'com.google.firebase:firebase-messaging:11.0.1'
compile 'com.firebaseui:firebase-ui-auth:2.0.1' 

Here is my Activity Code:

public class TestActivity extends AppCompatActivity {
    private RecyclerView recyclerView;
    private FirebaseUser mAuth;
    private DatabaseReference db;
    private String uid;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test);
        recyclerView=(RecyclerView) findViewById(R.id.userView);
       // mAuth= FirebaseAuth.getInstance().getCurrentUser();
        //uid=mAuth.getUid();
        db= FirebaseDatabase.getInstance().getReference().child("Users");
        recyclerView.setHasFixedSize(true);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        FirebaseRecyclerAdapter<AllUsers,userViewHolder> adapter=new FirebaseRecyclerAdapter<AllUsers, userViewHolder>(
                AllUsers.class,
                R.layout.add_people,
                userViewHolder.class,
                db
        ) {
            @Override
            protected void populateViewHolder(userViewHolder viewHolder, AllUsers model, int position) {
                viewHolder.setName(model.getName());
            }
        };
        recyclerView.setAdapter(adapter);
    }
    public static class userViewHolder extends RecyclerView.ViewHolder{
        View mview;
        public userViewHolder(View itemView) {
            super(itemView);
            mview=itemView;
        }
        public void setName(String name){
            TextView username=(TextView) mview.findViewById(R.id.addName);
            username.setText(name);
        }
    }
}

Here is my Modal Class:

public class AllUsers {
    public String Name;
    public String Status;
    public String Profile_pic;
    public AllUsers(){

    }

    public AllUsers(String name, String status, String profile_pic) {
        Name = name;
        Status = status;
        Profile_pic = profile_pic;
    }

    public String getName() {
        return Name;
    }

    public void setname(String name) {
        Name = name;
    }

    public String getStatus() {
        return Status;
    }

    public void setStatus(String status) {
        Status = status;
    }

    public String getProfile_pic() {
        return Profile_pic;
    }

    public void setProfile_pic(String profile_pic) {
        Profile_pic = profile_pic;
    }
}

Please help me. I dont know what is my mistake. I have tried a lot of codes but all in vain. I will be very thankful to you if you help me. Thanks a lot.

CEO tech4lifeapps
  • 885
  • 1
  • 12
  • 31
Haseeb
  • 23
  • 1
  • 8
  • 1
    Please post crash logs. – Jaymin May 24 '18 at 08:48
  • how to get crash logs?? I am new to android – Haseeb May 24 '18 at 08:50
  • https://developer.android.com/studio/debug/am-logcat will help you. – Jaymin May 24 '18 at 08:55
  • 05-24 14:07:54.760 13917-13917/com.myapper.hasee.stack I/dalvikvm: DexOpt: unable to optimize static field ref 0x002c at 0x3e in Lai;.a 05-24 14:07:54.775 13917-13917/com.myapper.hasee.stack I/AppCompatViewInflater: app:theme is now deprecated. Please move to using android:theme instead. – Haseeb May 24 '18 at 09:09
  • This is the last message that i found in LOGCAT. – Haseeb May 24 '18 at 09:10
  • 1
    Those are general logs. You're looking for [the stack trace](http://stackoverflow.com/questions/23353173) from the crash, which should be a large section of red lines. – Mike M. May 24 '18 at 09:12
  • I think you need to add Snapshot parser and FirebaseRecyclerViewOptions with the Recycler view adapter – Harsh Jain May 24 '18 at 10:08
  • @harshjain It looks like OP is using version 2.x of FirebaseUI, which didn't yet have `FirebaseRecyclerViewOptions`. Their constructor looks fine against that version. If they were using a newer/incompatible version, that would surface as a compile time error, not as a run time crash. – Frank van Puffelen May 24 '18 at 13:44
  • @FrankvanPuffelen How can i solve it?? You can see my all firebase dependecies?? – Haseeb May 25 '18 at 09:48
  • If you app crashed, there is a stack trace in your logcat for it. Seeing that is the most likely way someone will be able to help you. – Frank van Puffelen May 25 '18 at 14:12

0 Answers0