Bertho Joris Bertho Joris - 2 years ago 102
Java Question

Failed to display data on RecyclerView

I'm following a tutorial on this Lapit Chat App - All Users Activity - Firebase Tutorials - Part 14. But i get my application to be corrupted when retrieving data from firebase. For previous tutorials all goes well without error. Just for this topic my app crashes. And all my code is the same as in the tutorial.

UserActivity.java

package com.bertho.chat;

import android.app.ProgressDialog;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.TextView;

import com.firebase.ui.database.FirebaseRecyclerAdapter;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;

public class UsersActivity extends AppCompatActivity {

private Toolbar mToolbar;
private RecyclerView mUsersList;
private DatabaseReference mUsersDatabase;
private ProgressDialog mDialog;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_users);

mDialog = new ProgressDialog(this);

mToolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(mToolbar);
getSupportActionBar().setTitle("User List");
getSupportActionBar().setDisplayHomeAsUpEnabled(true);

mUsersDatabase = FirebaseDatabase.getInstance().getReference().child("Users");

mUsersList = (RecyclerView) findViewById(R.id.users_list);
mUsersList.setHasFixedSize(true);
mUsersList.setLayoutManager(new LinearLayoutManager(this));

}

@Override
protected void onStart() {
super.onStart();

showLoading("Get all user data");

FirebaseRecyclerAdapter<Users, UsersViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<Users, UsersViewHolder>(
Users.class,
R.layout.users_single_layout,
UsersViewHolder.class,
mUsersDatabase
) {
@Override
protected void populateViewHolder(UsersViewHolder usersViewHolder, Users users, int position) {
usersViewHolder.setDisplayName(users.getName());
mDialog.dismiss();
}
};

mUsersList.setAdapter(firebaseRecyclerAdapter);
}

public static class UsersViewHolder extends RecyclerView.ViewHolder {

View mView;

public UsersViewHolder(View itemView) {
super(itemView);

mView = itemView;
}

public void setDisplayName(String name) {
TextView userNameView = (TextView) mView.findViewById(R.id.user_single_name);
userNameView.setText(name);
}
}

private void showLoading(String s) {
mDialog.setTitle("Please waiting");
mDialog.setMessage(s);
mDialog.setCanceledOnTouchOutside(false);
mDialog.show();
}
}


activity_users.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.bertho.chat.UsersActivity">

<include layout="@layout/app_bar_layout"
android:id="@+id/user_appBar">
</include>

<android.support.v7.widget.RecyclerView
android:id="@+id/users_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/user_appBar">
</android.support.v7.widget.RecyclerView>

</RelativeLayout>


users_single_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="@color/bgAbuAbu">

<android.support.v4.widget.CircleImageView
android:id="@+id/user_single_image"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_margin="10dp"
android:src="@drawable/notfound" />

<TextView
android:id="@+id/user_single_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/user_single_image"
android:layout_marginTop="14dp"
android:layout_toEndOf="@+id/user_single_image"
android:layout_toRightOf="@+id/user_single_image"
android:text="User default name!"
android:textColor="@android:color/black"
android:textSize="16sp"
android:textStyle="bold" />

<TextView
android:id="@+id/user_single_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/user_single_name"
android:layout_marginTop="11dp"
android:layout_toEndOf="@+id/user_single_image"
android:layout_toRightOf="@+id/user_single_image"
android:text="User default status!" />

</RelativeLayout>


And my of Error Log on android studio
https://pastebin.com/UKhPswXQ

Is there anything wrong or missing on my code? Please help

Answer Source

your CircularImageView is not inflated and there was so many problems about it, solution use alternative library like hdodenhof CircularImageView link

add this to your dependencies :

compile 'de.hdodenhof:circleimageview:2.1.0'

and add the view like this :

<de.hdodenhof.circleimageview.CircleImageView
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/profile_image"
    android:layout_width="96dp"
    android:layout_height="96dp"
    android:src="@drawable/profile"
    app:civ_border_width="2dp"
    app:civ_border_color="#FF000000"/>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download