I'm simply just trying to populate data from Firebase Database into my recyclerview. My recyclerview shows perfectly, but the adapter won't set the values to the text in recyclerview textview, All it says is " No setter/field for -L57t4-97c3dLZjA_yXC found on class com.example.barry.starcity.StreetClass". Which makes me think that I didn't have my setters made correctly, but there was auto-generated by Android Studio. I don't know what I am missing here. Any help is appreciated.
NODE OBJECT
class StreetClass {
private String id;
private String semail;
private String sname;
private String stype;
private String sdetail;
private String slocation;
private String sdate;
private String imgurl;
public StreetClass(){
}
public String getImgurl() {
return imgurl;
}
public void setImgurl(String imgurl) {
this.imgurl = imgurl;
}
public String getId() {return id;}
public void setId(String id) {
this.id = id;
}
public String getEmail() {
return semail;
}
public void setEmail(String email) {
this.semail = email;
}
public String getName() {
return sname;
}
public void setName(String name) {
this.sname = name;
}
public String getType() {
return stype;
}
public void setType(String type) {
this.stype = type;
}
public String getDetail() {
return sdetail;
}
public void setDetail(String detail) {
this.sdetail = detail;
}
public String getLocation() {
return slocation;
}
public void setLocation(String location) {
this.slocation = location;
}
public String getDate() {
return sdate;
}
public void setDate(String date) {
this.sdate = date;
}
}
RecyclerViewAdapter
public class RecyclerViewAdapter extends
RecyclerView.Adapter<RecyclerViewAdapter.ViewHolder> {
Context context;
List<StreetClass>listdata ;
public RecyclerViewAdapter(Context context, List<StreetClass> list) {
this.listdata = list;
this.context = context;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.recyclerview_items, parent, false);
ViewHolder viewHolder = new ViewHolder(view);
return viewHolder;
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
StreetClass AllDetails = listdata.get(position);
holder.NameTextView.setText(AllDetails.getName());
holder.DetailTextView.setText(AllDetails.getDetail());
holder.EmailTextView.setText(AllDetails.getEmail());
holder.DateTextView.setText(AllDetails.getDate());
holder.LocationTextView.setText(AllDetails.getLocation());
holder.TypeTextView.setText(AllDetails.getType());
}
@Override
public int getItemCount() {
return listdata.size();
}
class ViewHolder extends RecyclerView.ViewHolder {
public TextView NameTextView;
public TextView DetailTextView;
public TextView EmailTextView;
public TextView DateTextView;
public TextView LocationTextView;
public TextView TypeTextView;
/*public ImageView ImageTextView;*/
public ViewHolder(View itemView) {
super(itemView);
NameTextView = itemView.findViewById(R.id.ShowNameTextView);
DetailTextView = itemView.findViewById(R.id.ShowDetailTextView);
EmailTextView = itemView.findViewById(R.id.ShowEmailTextView);
DateTextView = itemView.findViewById(R.id.ShowDateTextView);
LocationTextView = itemView.findViewById(R.id.ShowLocationTextView);
TypeTextView = itemView.findViewById(R.id.ShowTypeTextView)
}
}
}
MainActivity
public class StatusFragment extends Fragment {
DatabaseReference databaseStatus;
ProgressDialog progressDialog;
List<StreetClass> list = new ArrayList<StreetClass>();
RecyclerView recyclerView;
RecyclerView.Adapter adapter;
public StatusFragment() {
// Required empty public constructor
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
View rootView = inflater.inflate(R.layout.fragment_status, container, false);
recyclerView = rootView.findViewById(R.id.recyclerView);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext().getApplicationContext()));
progressDialog = new ProgressDialog(getActivity());
progressDialog.setMessage("Loading Data from Firebase Database");
progressDialog.show();
databaseStatus = FirebaseDatabase.getInstance().getReference().child("Street Problems");
databaseStatus.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
for (DataSnapshot dataSnapshot : snapshot.getChildren()) {
StreetClass streetClass = dataSnapshot.getValue(StreetClass.class);
list.add(streetClass);
}
adapter = new RecyclerViewAdapter(getContext().getApplicationContext(), list);
recyclerView.setAdapter(adapter);
adapter.notifyDataSetChanged();
progressDialog.dismiss();
}
@Override
public void onCancelled(DatabaseError databaseError) {
progressDialog.dismiss();
}
});
return rootView;
}
And the layout of an item:
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/cardview1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
card_view:cardElevation="5dp"
card_view:contentPadding="5dp"
card_view:cardCornerRadius="5dp"
card_view:cardMaxElevation="5dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ECEFF1"
android:padding="10dp">
<TextView
android:id="@+id/Name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Student Name: "
android:textColor="#000"
android:textSize="10dp" />
<TextView
android:id="@+id/Detail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Detail: "
android:textColor="#000"
android:textSize="10dp"
android:layout_below="@+id/Name"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:id="@+id/Email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Email: "
android:textColor="#000"
android:textSize="10dp"
android:layout_below="@+id/Detail"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:id="@+id/Date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Date: "
android:textColor="#000"
android:textSize="10dp"
android:layout_below="@+id/Email"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:id="@+id/Location"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Location "
android:textColor="#000"
android:textSize="10dp"
android:layout_below="@+id/Date"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<!-- <TextView
android:id="@+id/Image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/Type"
android:layout_toStartOf="@+id/ShowNameTextView"
android:text="Uploaded image: "
android:textColor="#000"
android:textSize="10dp" />-->
<TextView
android:id="@+id/Type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Type: "
android:textColor="#000"
android:textSize="10dp"
android:layout_below="@+id/Location"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:id="@+id/ShowNameTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Show Student Name"
android:textColor="#000"
android:textSize="10dp"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/Name"
android:layout_toEndOf="@+id/Name"
android:layout_marginLeft="19dp"
android:layout_marginStart="19dp" />
<TextView
android:id="@+id/ShowDetailTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="@+id/ShowNameTextView"
android:layout_below="@+id/ShowNameTextView"
android:gravity="center"
android:text="Show Detail"
android:textColor="#000"
android:textSize="10dp" />
<TextView
android:id="@+id/ShowEmailTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="@+id/ShowNameTextView"
android:layout_below="@+id/ShowDetailTextView"
android:gravity="center"
android:text="Show Email"
android:textColor="#000"
android:textSize="10dp" />
<TextView
android:id="@+id/ShowDateTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="@+id/ShowEmailTextView"
android:layout_below="@+id/ShowEmailTextView"
android:gravity="center"
android:text="Show Date"
android:textColor="#000"
android:textSize="10dp" />
<TextView
android:id="@+id/ShowLocationTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="@+id/ShowDateTextView"
android:layout_below="@+id/ShowDateTextView"
android:gravity="center"
android:text="Show Location"
android:textColor="#000"
android:textSize="10dp" />
<TextView
android:id="@+id/ShowTypeTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="@+id/ShowDateTextView"
android:layout_below="@+id/ShowLocationTextView"
android:gravity="center"
android:text="Show Type"
android:textColor="#000"
android:textSize="10dp" />
<!-- <android.support.v7.widget.AppCompatImageView
android:id="@+id/ShowImageView"
android:layout_width="90dp"
android:layout_height="50dp"
android:layout_alignStart="@+id/ShowTypeTextView"
android:layout_below="@+id/ShowTypeTextView" />-->
</RelativeLayout>
</android.support.v7.widget.CardView>
This is my database structure
java.lang.NullPointerException: Attempt to invoke virtual method 'void
android.support.v7.widget.RecyclerView.setHasFixedSize(boolean)' on a
null object reference
This is my Log cat
see this is my new database
In my App it looks like this
Logcat