My app crashes when i try to access the data from firestore and display it in a listview fragment class.Any help would be beneficial for me
availablestudent_fragment.java(main fragment class)
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.google.firebase.firestore.DocumentChange;
import com.google.firebase.firestore.DocumentSnapshot;
import com.google.firebase.firestore.EventListener;
import com.google.firebase.firestore.FirebaseFirestore;
import com.google.firebase.firestore.FirebaseFirestoreException;
import com.google.firebase.firestore.QuerySnapshot;
import com.google.firebase.firestore.auth.User;
import java.util.ArrayList;
import java.util.List;
public class availablestudent_fragment extends Fragment {
private static final String TAG ="FireLog" ;
private RecyclerView nmainlist;
private FirebaseFirestore mfirestore;
private List<Users> usersList;
private UserListAdapter userListAdapter;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v=inflater.inflate(R.layout.fragment_availablestudents,null);
nmainlist=(RecyclerView)v.findViewById(R.id.main_list);
nmainlist.setHasFixedSize(true);
nmainlist.setLayoutManager(new LinearLayoutManager(getContext()));
nmainlist.setAdapter(userListAdapter);
mfirestore=FirebaseFirestore.getInstance();
usersList=new ArrayList<>();
userListAdapter=new UserListAdapter(usersList);
mfirestore.collection("users").addSnapshotListener(new EventListener<QuerySnapshot>() {
@Override
public void onEvent(@javax.annotation.Nullable QuerySnapshot queryDocumentSnapshots, @javax.annotation.Nullable FirebaseFirestoreException e) {
if (e != null) {
Log.d(TAG, "Error" + e.getMessage());
}
for (DocumentChange doc : queryDocumentSnapshots.getDocumentChanges()) {
if (doc.getType() == DocumentChange.Type.ADDED) {
Users users = doc.getDocument().toObject(Users.class);
usersList.add(users);
userListAdapter.notifyDataSetChanged();
}
}
}
});
return v;
}
}
users.java(model class)
package com.kiit.projectmanager;
public class Users {
String Student_Name,Roll_Number;
public Users(){
}
public Users(String student_Name, String roll_Number) {
this.Student_Name = student_Name;
this.Roll_Number = roll_Number;
}
public String getStudent_Name() {
return Student_Name;
}
public void setStudent_Name(String student_Name) {
this.Student_Name = student_Name;
}
public String getRoll_Number() {
return Roll_Number;
}
public void setRoll_Number(String roll_Number) {
this.Roll_Number = roll_Number;
}
}
UsersListAdapter.java
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.google.firebase.firestore.auth.User;
import org.w3c.dom.Text;
import java.util.List;
public class UserListAdapter extends RecyclerView.Adapter<UserListAdapter.ViewHolder> {
public List<Users> usersList;
public UserListAdapter(List<Users> usersList){
this.usersList=usersList;
}
@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int i) {
View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item,parent,false);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
holder.StudentName.setText(usersList.get(position).getStudent_Name());
holder.RollNumber.setText(usersList.get(position).getRoll_Number());
}
@Override
public int getItemCount() {
return usersList.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
View mview;
public TextView StudentName;
public TextView RollNumber;
public ViewHolder(@NonNull View itemView) {
super(itemView);
mview=itemView;
StudentName=(TextView)mview.findViewById(R.id.name);
RollNumber=(TextView)mview.findViewById(R.id.rollnumber);
}
}
}
list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="13dp"
android:padding="13dp">
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/mirza_semibold"
android:text="NAME"
android:textColor="@color/common_google_signin_btn_text_dark_focused"
android:textSize="18dp" />
<TextView
android:id="@+id/rollnumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/fjalla_one"
android:text="ROLLNUMBER"
android:textColor="@color/common_google_signin_btn_text_dark_focused"
android:textSize="14dp" />
</LinearLayout>
Fragment_availablestudents.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/main_list"
android:layout_width="match_parent"
android:layout_height="match_parent"></android.support.v7.widget.RecyclerView>
</LinearLayout>
logcat_Error ( here my app crashes when i try to click on my fragment)
03-29 19:28:58.838 18481-18677/com.kiit.projectmanager I/OpenGLRenderer: Initialized EGL, version 1.4
03-29 19:28:58.876 18481-18481/com.kiit.projectmanager W/art: Before Android 4.1, method int android.support.v7.widget.DropDownListView.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView
03-29 19:28:58.956 18481-18677/com.kiit.projectmanager E/HAL: hw_get_module_by_class: module name gralloc
03-29 19:28:58.956 18481-18677/com.kiit.projectmanager E/HAL: hw_get_module_by_class: module name gralloc
03-29 19:28:59.054 18481-18638/com.kiit.projectmanager D/FA: Connected to remote service
03-29 19:28:59.900 18481-18481/com.kiit.projectmanager I/Timeline: Timeline: Activity_launch_request time:50369167
03-29 19:28:59.920 18481-18638/com.kiit.projectmanager D/FA: Logging event (FE): user_engagement(_e), Bundle[{firebase_event_origin(_o)=auto, engagement_time_msec(_et)=1162, firebase_screen_class(_sc)=MainActivity, firebase_screen_id(_si)=9078248192392117239}]
03-29 19:29:00.229 18481-18638/com.kiit.projectmanager D/FA: Logging event (FE): screen_view(_vs), Bundle[{firebase_event_origin(_o)=auto, firebase_previous_class(_pc)=MainActivity, firebase_previous_id(_pi)=9078248192392117239, firebase_screen_class(_sc)=login_activity, firebase_screen_id(_si)=9078248192392117240}]
03-29 19:29:02.730 18481-18481/com.kiit.projectmanager I/Choreographer: Skipped 146 frames! The application may be doing too much work on its main thread.
03-29 19:29:04.698 18481-18481/com.kiit.projectmanager I/Choreographer: Skipped 117 frames! The application may be doing too much work on its main thread.
03-29 19:29:04.705 18481-18481/com.kiit.projectmanager I/Timeline: Timeline: Activity_launch_request time:50373972
03-29 19:29:04.724 18481-18638/com.kiit.projectmanager D/FA: Logging event (FE): user_engagement(_e), Bundle[{firebase_event_origin(_o)=auto, engagement_time_msec(_et)=4492, firebase_screen_class(_sc)=login_activity, firebase_screen_id(_si)=9078248192392117240}]
03-29 19:29:04.763 18481-18638/com.kiit.projectmanager D/FA: Logging event (FE): screen_view(_vs), Bundle[{firebase_event_origin(_o)=auto, firebase_previous_class(_pc)=login_activity, firebase_previous_id(_pi)=9078248192392117240, firebase_screen_class(_sc)=student_login, firebase_screen_id(_si)=9078248192392117241}]
03-29 19:29:07.105 18481-18481/com.kiit.projectmanager E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
03-29 19:29:07.105 18481-18481/com.kiit.projectmanager E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
03-29 19:29:10.300 18481-18638/com.kiit.projectmanager D/FA: Setting user property (FE): _sid, 1553867950
03-29 19:29:10.341 18481-18638/com.kiit.projectmanager D/FA: Logging event (FE): session_start(_s), Bundle[{firebase_event_origin(_o)=auto, firebase_screen_class(_sc)=student_login, firebase_screen_id(_si)=9078248192392117241, session_id(_sid)=1553867950}]
03-29 19:29:10.376 18481-18638/com.kiit.projectmanager D/FA: Connected to remote service
03-29 19:29:11.005 18481-18481/com.kiit.projectmanager E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
03-29 19:29:11.005 18481-18481/com.kiit.projectmanager E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
03-29 19:29:11.666 18481-18481/com.kiit.projectmanager E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
03-29 19:29:11.666 18481-18481/com.kiit.projectmanager E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
03-29 19:29:15.494 18481-18481/com.kiit.projectmanager W/IInputConnectionWrapper: getExtractedText on inactive InputConnection
03-29 19:29:15.497 18481-18481/com.kiit.projectmanager W/IInputConnectionWrapper: getTextBeforeCursor on inactive InputConnection
03-29 19:29:15.499 18481-18481/com.kiit.projectmanager W/IInputConnectionWrapper: setComposingRegion on inactive InputConnection
03-29 19:29:19.178 18481-18481/com.kiit.projectmanager W/BiChannelGoogleApi: [FirebaseAuth: ] getGoogleApiForMethod() returned Gms: com.google.firebase.auth.api.internal.zzal@8cbf476
03-29 19:29:20.161 18481-18481/com.kiit.projectmanager I/Toast: Show toast from OpPackageName:com.kiit.projectmanager, PackageName:com.kiit.projectmanager
03-29 19:29:24.288 18481-18481/com.kiit.projectmanager W/BiChannelGoogleApi: [FirebaseAuth: ] getGoogleApiForMethod() returned Gms: com.google.firebase.auth.api.internal.zzal@8cbf476
03-29 19:29:24.781 18481-18481/com.kiit.projectmanager I/Toast: Show toast from OpPackageName:com.kiit.projectmanager, PackageName:com.kiit.projectmanager
03-29 19:29:29.533 18481-18481/com.kiit.projectmanager E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
03-29 19:29:29.533 18481-18481/com.kiit.projectmanager E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
03-29 19:29:30.249 18481-18481/com.kiit.projectmanager E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
03-29 19:29:30.250 18481-18481/com.kiit.projectmanager E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
03-29 19:29:30.320 18481-18481/com.kiit.projectmanager E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
03-29 19:29:30.320 18481-18481/com.kiit.projectmanager E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
03-29 19:29:32.446 18481-18481/com.kiit.projectmanager E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
03-29 19:29:32.446 18481-18481/com.kiit.projectmanager E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
03-29 19:29:32.769 18481-18481/com.kiit.projectmanager E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
03-29 19:29:32.769 18481-18481/com.kiit.projectmanager E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
03-29 19:29:36.362 18481-18481/com.kiit.projectmanager E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
03-29 19:29:36.362 18481-18481/com.kiit.projectmanager E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
03-29 19:29:42.405 18481-18481/com.kiit.projectmanager W/BiChannelGoogleApi: [FirebaseAuth: ] getGoogleApiForMethod() returned Gms: com.google.firebase.auth.api.internal.zzal@8cbf476
03-29 19:29:44.406 18481-18583/com.kiit.projectmanager D/FirebaseAuth: Notifying id token listeners about user ( yBhPtTpYDdQgviffTlUvhLwAOPn1 ).
03-29 19:29:44.420 18481-18481/com.kiit.projectmanager D/FirebaseApp: Notifying auth state listeners.
03-29 19:29:44.420 18481-18481/com.kiit.projectmanager D/FirebaseApp: Notified 0 auth state listeners.
03-29 19:29:44.437 18481-18481/com.kiit.projectmanager I/Timeline: Timeline: Activity_launch_request time:50413704
03-29 19:29:44.475 18481-18638/com.kiit.projectmanager D/FA: Logging event (FE): user_engagement(_e), Bundle[{firebase_event_origin(_o)=auto, engagement_time_msec(_et)=39712, firebase_screen_class(_sc)=student_login, firebase_screen_id(_si)=9078248192392117241}]
03-29 19:29:44.646 18481-19899/com.kiit.projectmanager W/DynamiteModule: Local module descriptor class for providerinstaller not found.
03-29 19:29:44.652 18481-18638/com.kiit.projectmanager D/FA: Logging event (FE): screen_view(_vs), Bundle[{firebase_event_origin(_o)=auto, firebase_previous_class(_pc)=student_login, firebase_previous_id(_pi)=9078248192392117241, firebase_screen_class(_sc)=student_activity, firebase_screen_id(_si)=9078248192392117242}]
03-29 19:29:44.655 18481-19899/com.kiit.projectmanager I/DynamiteModule: Considering local module providerinstaller:0 and remote module providerinstaller:0
03-29 19:29:44.655 18481-19899/com.kiit.projectmanager W/ProviderInstaller: Failed to load providerinstaller module: No acceptable module found. Local version is 0 and remote version is 0.
03-29 19:29:44.656 18481-19899/com.kiit.projectmanager W/ResourceType: No package identifier when getting name for resource number 0x00000000
03-29 19:29:44.817 18481-18638/com.kiit.projectmanager D/FA: Connected to remote service
03-29 19:29:44.884 18481-19899/com.kiit.projectmanager I/art: Rejecting re-init on previously-failed class java.lang.Class<com.google.android.gms.org.conscrypt.Java7ExtendedSSLSession>
03-29 19:29:44.885 18481-19899/com.kiit.projectmanager I/art: Rejecting re-init on previously-failed class java.lang.Class<com.google.android.gms.org.conscrypt.Java7ExtendedSSLSession>
03-29 19:29:44.888 18481-19899/com.kiit.projectmanager I/art: Rejecting re-init on previously-failed class java.lang.Class<com.google.android.gms.org.conscrypt.Java8ExtendedSSLSession>
03-29 19:29:44.889 18481-19899/com.kiit.projectmanager I/art: Rejecting re-init on previously-failed class java.lang.Class<com.google.android.gms.org.conscrypt.Java8ExtendedSSLSession>
03-29 19:29:44.946 18481-19899/com.kiit.projectmanager I/ProviderInstaller: Installed default security provider GmsCore_OpenSSL
03-29 19:29:45.890 18481-18481/com.kiit.projectmanager W/PathParser: Points are too far apart 4.000000596046461
03-29 19:29:48.115 18481-18481/com.kiit.projectmanager E/RecyclerView: No adapter attached; skipping layout
03-29 19:29:48.134 18481-18481/com.kiit.projectmanager W/PathParser: Points are too far apart 4.000000596046461
03-29 19:29:48.467 18481-18481/com.kiit.projectmanager D/AndroidRuntime: Shutting down VM
03-29 19:29:48.468 18481-18481/com.kiit.projectmanager E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.kiit.projectmanager, PID: 18481
java.lang.RuntimeException: Found two getters or fields with conflicting case sensitivity for property: roll_number
at com.google.firebase.firestore.util.CustomClassMapper$BeanMapper.addProperty(com.google.firebase:firebase-firestore@@18.1.0:670)
at com.google.firebase.firestore.util.CustomClassMapper$BeanMapper.<init>(com.google.firebase:firebase-firestore@@18.1.0:586)
at com.google.firebase.firestore.util.CustomClassMapper.loadOrCreateBeanMapperForClass(com.google.firebase:firebase-firestore@@18.1.0:348)
at com.google.firebase.firestore.util.CustomClassMapper.convertBean(com.google.firebase:firebase-firestore@@18.1.0:502)
at com.google.firebase.firestore.util.CustomClassMapper.deserializeToClass(com.google.firebase:firebase-firestore@@18.1.0:243)
at com.google.firebase.firestore.util.CustomClassMapper.convertToCustomClass(com.google.firebase:firebase-firestore@@18.1.0:97)
at com.google.firebase.firestore.DocumentSnapshot.toObject(com.google.firebase:firebase-firestore@@18.1.0:203)
at com.google.firebase.firestore.QueryDocumentSnapshot.toObject(com.google.firebase:firebase-firestore@@18.1.0:121)
at com.google.firebase.firestore.DocumentSnapshot.toObject(com.google.firebase:firebase-firestore@@18.1.0:183)
at com.google.firebase.firestore.QueryDocumentSnapshot.toObject(com.google.firebase:firebase-firestore@@18.1.0:101)
at com.kiit.projectmanager.availablestudent_fragment$1.onEvent(availablestudent_fragment.java:59)
at com.kiit.projectmanager.availablestudent_fragment$1.onEvent(availablestudent_fragment.java:48)
at com.google.firebase.firestore.Query.lambda$addSnapshotListenerInternal$2(com.google.firebase:firebase-firestore@@18.1.0:891)
at com.google.firebase.firestore.Query$$Lambda$3.onEvent(com.google.firebase:firebase-firestore@@18.1.0)
at com.google.firebase.firestore.util.ExecutorEventListener.lambda$onEvent$0(com.google.firebase:firebase-firestore@@18.1.0:42)
at com.google.firebase.firestore.util.ExecutorEventListener$$Lambda$1.run(com.google.firebase:firebase-firestore@@18.1.0)
at android.os.Handler.handleCallback(Handler.java:742)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5603)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:774)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:652)
03-29 19:29:58.480 18481-19899/com.kiit.projectmanager W/Firestore: (18.1.0) [OnlineStateTracker]: Could not reach Cloud Firestore backend. Backend didn't respond within 10 seconds
This typically indicates that your device does not have a healthy Internet connection at the moment. The client will operate in offline mode until it is able to successfully connect to the backend.
Error retrieve from cell to make it more clear
java.lang.RuntimeException: Found two getters or fields with conflicting case sensitivity for property: roll_number
at com.google.firebase.firestore.util.CustomClassMapper$BeanMapper.addProperty(com.google.firebase:firebase-firestore@@18.1.0:670)
at com.google.firebase.firestore.util.CustomClassMapper$BeanMapper.<init>(com.google.firebase:firebase-firestore@@18.1.0:586)
at com.google.firebase.firestore.util.CustomClassMapper.loadOrCreateBeanMapperForClass(com.google.firebase:firebase-firestore@@18.1.0:348)
at com.google.firebase.firestore.util.CustomClassMapper.convertBean(com.google.firebase:firebase-firestore@@18.1.0:502)
at com.google.firebase.firestore.util.CustomClassMapper.deserializeToClass(com.google.firebase:firebase-firestore@@18.1.0:243)
at com.google.firebase.firestore.util.CustomClassMapper.convertToCustomClass(com.google.firebase:firebase-firestore@@18.1.0:97)
at com.google.firebase.firestore.DocumentSnapshot.toObject(com.google.firebase:firebase-firestore@@18.1.0:203)
at com.google.firebase.firestore.QueryDocumentSnapshot.toObject(com.google.firebase:firebase-firestore@@18.1.0:121)
at com.google.firebase.firestore.DocumentSnapshot.toObject(com.google.firebase:firebase-firestore@@18.1.0:183)
at com.google.firebase.firestore.QueryDocumentSnapshot.toObject(com.google.firebase:firebase-firestore@@18.1.0:101)
at com.kiit.projectmanager.availablestudent_fragment$1.onEvent(availablestudent_fragment.java:59)
at com.kiit.projectmanager.availablestudent_fragment$1.onEvent(availablestudent_fragment.java:48)
at com.google.firebase.firestore.Query.lambda$addSnapshotListenerInternal$2(com.google.firebase:firebase-firestore@@18.1.0:891)
at com.google.firebase.firestore.Query$$Lambda$3.onEvent(com.google.firebase:firebase-firestore@@18.1.0)
at com.google.firebase.firestore.util.ExecutorEventListener.lambda$onEvent$0(com.google.firebase:firebase-firestore@@18.1.0:42)
at com.google.firebase.firestore.util.ExecutorEventListener$$Lambda$1.run(com.google.firebase:firebase-firestore@@18.1.0)
at android.os.Handler.handleCallback(Handler.java:742)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5603)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:774)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:652)
To solve this, you need to fix the capitalization on your fields and methods in your Users
class according to Java Naming Conventions. So your model class should look like this:
public class Users {
String studentName, rollNumber;
public Users(){}
public Users(String studentName, String rollNumber) {
this.studentName = studentName;
this.rollNumber = rollNumber;
}
public String getStudentName() {
return studentName;
}
public void setStudentName(String studentName) {
this.studentName = studentName;
}
public String getRollNumber() {
return rollNumber;
}
public void setRollNumber(String rollNumber) {
this.rollNumber = rollNumber;
}
}
Delete old data, add new data and everything will work fine.
User contributions licensed under CC BY-SA 3.0