I need help. I am trying to get the data stored in firestore firebase in to a recycler i find many tutorials and i followed exactely as the tutorial. but when i run my application a number of cardview are created (the same amount of data in firestore) but instead of puting the data into the card it says null for some reason.
this is the fragment
public class MedicineFragment extends Fragment {
FloatingActionButton floatingActionButton;
private FirebaseAuth firebaseAuth;
public FirebaseFirestore firebaseFirestore = FirebaseFirestore.getInstance();
public CollectionReference DrugRef = firebaseFirestore.collection("Drug Info");
private DrugAdaper adapter;
FirebaseUser user;
private RecyclerView mfirestoreList;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View root = inflater.inflate(R.layout.fragment_medicine, container, false);
FloatingActionButton floatingActionButton = root.findViewById(R.id.floating);
floatingActionButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
callBottomSheet();
}
});
firebaseAuth = FirebaseAuth.getInstance();
mfirestoreList = root.findViewById(R.id.firestore_list);
//mfirestoreList.setHasFixedSize(true);
setUpRecycleView();
return root;
}
public void setUpRecycleView() {
Query query = FirebaseFirestore.getInstance().collection("Drug Info");
// getting query into adapter
FirestoreRecyclerOptions<DrugModel> options = new FirestoreRecyclerOptions.Builder<DrugModel>()
.setQuery(query, DrugModel.class)
.build();
adapter = new DrugAdaper(options);
LinearLayoutManager linearLayout = new LinearLayoutManager(getContext(),LinearLayoutManager.VERTICAL, false);
//recyclerView.setHasFixedSize(true);
mfirestoreList.setLayoutManager(linearLayout);
adapter.startListening();
adapter.notifyDataSetChanged();
mfirestoreList.setAdapter(adapter);
}
private void callBottomSheet() {
final View view = getLayoutInflater().inflate(R.layout.bottom_sheet, null);
final BottomSheetDialog dialog = new BottomSheetDialog(getContext());
dialog.setContentView(view);
dialog.show();
Button add= view.findViewById(R.id.addButton);
add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final TextInputEditText name = view.findViewById(R.id.itemName);
final TextInputEditText formula = view.findViewById(R.id.itemFormula);
final TextInputEditText price = view.findViewById(R.id.itemPrice);
user = firebaseAuth.getCurrentUser();
Map<String, Object> drugInfo = new HashMap<>();
drugInfo.put("Name", name.getText().toString().trim() );
drugInfo.put("Formula", formula.getText().toString().trim());
drugInfo.put("Price", Integer.parseInt(price.getText().toString().trim()) );
drugInfo.put("User", firebaseAuth.getCurrentUser().getUid());
String userName = user.getEmail().toString();
firebaseFirestore.collection("Drug Info").document().set(drugInfo)
.addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
Toast.makeText(getContext(), "Saved", Toast.LENGTH_LONG).show();
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(getContext(), "Failed to add data", Toast.LENGTH_LONG).show();
}
});
dialog.hide();
}
});
}
@Override
public void onStart() {
super.onStart();
if (adapter != null) {
adapter.startListening();
}
//readDocument();
}
@Override
public void onStop() {
super.onStop();
if (adapter != null) {
adapter.startListening();
}
}
@Override
public void onDestroyView() {
super.onDestroyView();
adapter.stopListening();
}
}
this is the model class i used
public class DrugModel {
String Drugname;
String DrugFormula;
String DrugPrice;
public DrugModel() {
}
public DrugModel(String drugname, String drugFormula, String drugPrice) {
Drugname = drugname;
DrugFormula = drugFormula;
DrugPrice = drugPrice;
}
public String getDrugname() {
return Drugname;
}
public String getDrugFormula() {
return DrugFormula;
}
public String getDrugPrice() {
return DrugPrice;
}
}
this is the adapter
public class DrugAdaper extends FirestoreRecyclerAdapter<DrugModel, DrugAdaper.DrugHolder> {
public DrugAdaper(@NonNull FirestoreRecyclerOptions<DrugModel> options) {
super(options);
}
@Override
protected void onBindViewHolder(@NonNull DrugHolder holder, int position, @NonNull DrugModel model) {
holder.drugName.setText(model.getDrugname());
holder.drugFormula.setText(model.getDrugFormula());
holder.drugPrice.setText(String.valueOf(model.getDrugPrice()));
}
@NonNull
@Override
public DrugHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.drug_item, parent, false);
return new DrugHolder(v);
}
class DrugHolder extends RecyclerView.ViewHolder
{
TextView drugName;
TextView drugFormula;
TextView drugPrice;
public DrugHolder(@NonNull View itemView) {
super(itemView);
drugName = itemView.findViewById(R.id.DrugName);
drugFormula = itemView.findViewById(R.id.DrugFormula);
drugPrice = itemView.findViewById(R.id.DrugPrice);
drugName.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(v.getContext(), drugName.getText().toString(), Toast.LENGTH_LONG ).show();
}
});
itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(v.getContext(), drugName.getText().toString(), Toast.LENGTH_LONG ).show();
}
});
}
}
@Override
public int getItemCount() {
return super.getItemCount();
}
}
run stack trace
01/26 17:59:30: Launching 'app' on Pixel 2 API 28.
Connected to process 18442 on device 'Pixel_2_API_28 [emulator-5554]'.
$ adb shell am start -n "com.example.e_pharmaphar_side/com.example.e_pharmaphar_side.SignUp_activity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Connected to process 18525 on device 'Pixel_2_API_28 [emulator-5554]'.
Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page.
W/ComponentDiscovery: Class com.google.firebase.dynamicloading.DynamicLoadingRegistrar is not an found.
I/FirebaseApp: Device unlocked: initializing all Firebase APIs for app [DEFAULT]
W/pharmaphar_sid: Unsupported class loader
W/pharmaphar_sid: Skipping duplicate class check due to unsupported classloader
I/DynamiteModule: Considering local module com.google.android.gms.measurement.dynamite:20 and remote module com.google.android.gms.measurement.dynamite:21
Selected remote version of com.google.android.gms.measurement.dynamite, version >= 21
V/DynamiteModule: Dynamite loader version >= 2, using loadModule2NoCrashUtils
D/FirebaseAuth: Notifying id token listeners about user ( yQc3RMLzw2VgnMCLf1TiWA6sdwQ2 ).
I/FirebaseInitProvider: FirebaseApp initialization successful
I/FirebaseAuth: [FirebaseAuth:] Preparing to create service connection to fallback implementation
W/pharmaphar_sid: Unknown chunk type '200'.
W/pharmaphar_sid: Unsupported class loader
W/pharmaphar_sid: Skipping duplicate class check due to unsupported classloader
W/pharmaphar_sid: Accessing hidden method Landroid/graphics/drawable/Drawable;->getOpticalInsets()Landroid/graphics/Insets; (light greylist, linking)
Accessing hidden field Landroid/graphics/Insets;->left:I (light greylist, linking)
Accessing hidden field Landroid/graphics/Insets;->right:I (light greylist, linking)
Accessing hidden field Landroid/graphics/Insets;->top:I (light greylist, linking)
Accessing hidden field Landroid/graphics/Insets;->bottom:I (light greylist, linking)
V/FA: onActivityCreated
W/pharmaphar_sid: Accessing hidden field Landroid/view/WindowInsets;->CONSUMED:Landroid/view/WindowInsets; (light greylist, reflection)
W/pharmaphar_sid: Accessing hidden method Landroid/view/View;->getAccessibilityDelegate()Landroid/view/View$AccessibilityDelegate; (light greylist, linking)
V/FA: App measurement collection enabled
V/FA: App measurement enabled for app package, google app id: com.example.e_pharmaphar_side, 1:489289635419:android:eb0abd39f3927b306ad17e
I/FA: App measurement initialized, version: 35000
To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
I/FA: To enable faster debug mode event logging run:
adb shell setprop debug.firebase.analytics.app com.example.e_pharmaphar_side
D/FA: Debug-level message logging enabled
W/pharmaphar_sid: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (light greylist, reflection)
W/pharmaphar_sid: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (light greylist, reflection)
V/FA: Connecting to remote service
V/FA: Connection attempt already in progress
V/FA: Connection attempt already in progress
V/FA: Activity resumed, time: 6469318
I/FA: Tag Manager is not found and thus will not be used
D/OpenGLRenderer: Skia GL Pipeline
W/pharmaphar_sid: Accessing hidden method Landroid/graphics/Insets;->of(IIII)Landroid/graphics/Insets; (light greylist, linking)
V/FA: Connection attempt already in progress
Connection attempt already in progress
V/FA: Screen exposed for less than 1000 ms. Event not sent. time: 49
Connection attempt already in progress
V/FA: Activity paused, time: 6469372
D/HostConnection: HostConnection::get() New Host Connection established 0xe7b2ac80, tid 18609
D/HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_dma_v1 ANDROID_EMU_YUV420_888_to_NV21 ANDROID_EMU_YUV_Cache ANDROID_EMU_async_unmap_buffer GL_OES_EGL_image_external_essl3 GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_gles_max_version_3_0
I/ConfigStore: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0
android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasHDRDisplay retrieved: 0
I/OpenGLRenderer: Initialized EGL, version 1.4
D/OpenGLRenderer: Swap behavior 1
W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
D/OpenGLRenderer: Swap behavior 0
D/eglCodecCommon: setVertexArrayObject: set vao to 0 (0) 0 0
D/EGL_emulation: eglCreateContext: 0xe7b05f00: maj 3 min 0 rcv 3
D/EGL_emulation: eglMakeCurrent: 0xe7b05f00: ver 3 0 (tinfo 0xd19dd060)
D/HostConnection: createUnique: call
D/HostConnection: HostConnection::get() New Host Connection established 0xe7b2ae10, tid 18609
D/HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_dma_v1 ANDROID_EMU_YUV420_888_to_NV21 ANDROID_EMU_YUV_Cache ANDROID_EMU_async_unmap_buffer GL_OES_EGL_image_external_essl3 GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_gles_max_version_3_0
W/ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy@78217ac
E/eglCodecCommon: GoldfishAddressSpaceHostMemoryAllocator: ioctl_ping failed for device_type=5, ret=-1
V/FA: onActivityCreated
W/DynamiteModule: Local module descriptor class for providerinstaller not found.
I/DynamiteModule: Considering local module providerinstaller:0 and remote module providerinstaller:0
W/ProviderInstaller: Failed to load providerinstaller module: No acceptable module found. Local version is 0 and remote version is 0.
V/FA: Activity resumed, time: 6469793
I/pharmaphar_sid: The ClassLoaderContext is a special shared library.
I/pharmaphar_sid: The ClassLoaderContext is a special shared library.
I/pharmaphar_sid: The ClassLoaderContext is a special shared library.
D/EGL_emulation: eglMakeCurrent: 0xe7b05f00: ver 3 0 (tinfo 0xd19dd060)
D/eglCodecCommon: setVertexArrayObject: set vao to 0 (0) 1 2
V/FA: Connection attempt already in progress
V/FA: Connection attempt already in progress
I/pharmaphar_sid: Background concurrent copying GC freed 14406(1192KB) AllocSpace objects, 6(248KB) LOS objects, 49% free, 3MB/6MB, paused 495us total 177.911ms
V/NativeCrypto: Registering com/google/android/gms/org/conscrypt/NativeCrypto's 286 native methods...
W/pharmaphar_sid: Accessing hidden field Ljava/nio/Buffer;->address:J (light greylist, reflection)
W/pharmaphar_sid: Accessing hidden method Ljava/security/spec/ECParameterSpec;->getCurveName()Ljava/lang/String; (light greylist, reflection)
W/pharmaphar_sid: Accessing hidden field Landroid/os/Trace;->TRACE_TAG_APP:J (light greylist, reflection)
W/pharmaphar_sid: Accessing hidden method Landroid/os/Trace;->isTagEnabled(J)Z (light greylist, reflection)
Accessing hidden method Landroid/os/Trace;->asyncTraceBegin(JLjava/lang/String;I)V (light greylist, reflection)
W/pharmaphar_sid: Accessing hidden method Landroid/os/Trace;->asyncTraceEnd(JLjava/lang/String;I)V (light greylist, reflection)
Accessing hidden method Landroid/os/Trace;->traceCounter(JLjava/lang/String;I)V (light greylist, reflection)
D/FA: Connected to remote service
I/Choreographer: Skipped 31 frames! The application may be doing too much work on its main thread.
V/FA: Processing queued up service tasks: 8
D/EGL_emulation: eglMakeCurrent: 0xe7b05f00: ver 3 0 (tinfo 0xd19dd060)
D/NetworkSecurityConfig: No Network Security Config specified, using platform default
I/ProviderInstaller: Installed default security provider GmsCore_OpenSSL
D/EGL_emulation: eglMakeCurrent: 0xe7b05f00: ver 3 0 (tinfo 0xd19dd060)
W/Firestore: (22.0.1) [CustomClassMapper]: No setter/field for Formula found on class com.example.e_pharmaphar_side.ui.DrugInfo
(22.0.1) [CustomClassMapper]: No setter/field for User found on class com.example.e_pharmaphar_side.ui.DrugInfo
(22.0.1) [CustomClassMapper]: No setter/field for Price found on class com.example.e_pharmaphar_side.ui.DrugInfo (fields/setters are case sensitive!)
(22.0.1) [CustomClassMapper]: No setter/field for Name found on class com.example.e_pharmaphar_side.ui.DrugInfo
W/Firestore: (22.0.1) [CustomClassMapper]: No setter/field for Formula found on class com.example.e_pharmaphar_side.ui.DrugInfo
W/Firestore: (22.0.1) [CustomClassMapper]: No setter/field for User found on class com.example.e_pharmaphar_side.ui.DrugInfo
(22.0.1) [CustomClassMapper]: No setter/field for Price found on class com.example.e_pharmaphar_side.ui.DrugInfo (fields/setters are case sensitive!)
(22.0.1) [CustomClassMapper]: No setter/field for Name found on class com.example.e_pharmaphar_side.ui.DrugInfo
W/Firestore: (22.0.1) [CustomClassMapper]: No setter/field for Formula found on class com.example.e_pharmaphar_side.ui.DrugInfo
W/Firestore: (22.0.1) [CustomClassMapper]: No setter/field for User found on class com.example.e_pharmaphar_side.ui.DrugInfo
(22.0.1) [CustomClassMapper]: No setter/field for Price found on class com.example.e_pharmaphar_side.ui.DrugInfo (fields/setters are case sensitive!)
(22.0.1) [CustomClassMapper]: No setter/field for Name found on class com.example.e_pharmaphar_side.ui.DrugInfo
W/Firestore: (22.0.1) [CustomClassMapper]: No setter/field for Formula found on class com.example.e_pharmaphar_side.ui.DrugInfo
(22.0.1) [CustomClassMapper]: No setter/field for User found on class com.example.e_pharmaphar_side.ui.DrugInfo
W/Firestore: (22.0.1) [CustomClassMapper]: No setter/field for Price found on class com.example.e_pharmaphar_side.ui.DrugInfo (fields/setters are case sensitive!)
(22.0.1) [CustomClassMapper]: No setter/field for Name found on class com.example.e_pharmaphar_side.ui.DrugInfo
W/Firestore: (22.0.1) [CustomClassMapper]: No setter/field for Formula found on class com.example.e_pharmaphar_side.ui.DrugInfo
W/Firestore: (22.0.1) [CustomClassMapper]: No setter/field for User found on class com.example.e_pharmaphar_side.ui.DrugInfo
(22.0.1) [CustomClassMapper]: No setter/field for Price found on class com.example.e_pharmaphar_side.ui.DrugInfo (fields/setters are case sensitive!)
(22.0.1) [CustomClassMapper]: No setter/field for Name found on class com.example.e_pharmaphar_side.ui.DrugInfo
W/Firestore: (22.0.1) [CustomClassMapper]: No setter/field for Formula found on class com.example.e_pharmaphar_side.ui.DrugInfo
W/Firestore: (22.0.1) [CustomClassMapper]: No setter/field for User found on class com.example.e_pharmaphar_side.ui.DrugInfo
(22.0.1) [CustomClassMapper]: No setter/field for Price found on class com.example.e_pharmaphar_side.ui.DrugInfo (fields/setters are case sensitive!)
(22.0.1) [CustomClassMapper]: No setter/field for Name found on class com.example.e_pharmaphar_side.ui.DrugInfo
W/pharmaphar_sid: Accessing hidden field Ljava/net/Socket;->impl:Ljava/net/SocketImpl; (light greylist, reflection)
W/pharmaphar_sid: Accessing hidden method Ldalvik/system/CloseGuard;->get()Ldalvik/system/CloseGuard; (light greylist, linking)
W/pharmaphar_sid: Accessing hidden method Ldalvik/system/CloseGuard;->open(Ljava/lang/String;)V (light greylist, linking)
W/pharmaphar_sid: Accessing hidden field Ljava/io/FileDescriptor;->descriptor:I (light greylist, JNI)
W/pharmaphar_sid: Accessing hidden method Ljava/security/spec/ECParameterSpec;->setCurveName(Ljava/lang/String;)V (light greylist, reflection)
W/pharmaphar_sid: Accessing hidden method Ldalvik/system/BlockGuard;->getThreadPolicy()Ldalvik/system/BlockGuard$Policy; (light greylist, linking)
Accessing hidden method Ldalvik/system/BlockGuard$Policy;->onNetwork()V (light greylist, linking)
W/Firestore: (22.0.1) [CustomClassMapper]: No setter/field for Formula found on class com.example.e_pharmaphar_side.ui.DrugInfo
(22.0.1) [CustomClassMapper]: No setter/field for User found on class com.example.e_pharmaphar_side.ui.DrugInfo
(22.0.1) [CustomClassMapper]: No setter/field for Price found on class com.example.e_pharmaphar_side.ui.DrugInfo (fields/setters are case sensitive!)
(22.0.1) [CustomClassMapper]: No setter/field for Name found on class com.example.e_pharmaphar_side.ui.DrugInfo
W/Firestore: (22.0.1) [CustomClassMapper]: No setter/field for Formula found on class com.example.e_pharmaphar_side.ui.DrugInfo
(22.0.1) [CustomClassMapper]: No setter/field for User found on class com.example.e_pharmaphar_side.ui.DrugInfo
(22.0.1) [CustomClassMapper]: No setter/field for Price found on class com.example.e_pharmaphar_side.ui.DrugInfo (fields/setters are case sensitive!)
W/Firestore: (22.0.1) [CustomClassMapper]: No setter/field for Name found on class com.example.e_pharmaphar_side.ui.DrugInfo
W/pharmaphar_sid: Accessing hidden field Landroid/view/View;->mAccessibilityDelegate:Landroid/view/View$AccessibilityDelegate; (light greylist, reflection)
W/Firestore: (22.0.1) [CustomClassMapper]: No setter/field for Formula found on class com.example.e_pharmaphar_side.ui.DrugInfo
W/Firestore: (22.0.1) [CustomClassMapper]: No setter/field for User found on class com.example.e_pharmaphar_side.ui.DrugInfo
(22.0.1) [CustomClassMapper]: No setter/field for Price found on class com.example.e_pharmaphar_side.ui.DrugInfo (fields/setters are case sensitive!)
(22.0.1) [CustomClassMapper]: No setter/field for Name found on class com.example.e_pharmaphar_side.ui.DrugInfo
W/Firestore: (22.0.1) [CustomClassMapper]: No setter/field for Formula found on class com.example.e_pharmaphar_side.ui.DrugInfo
(22.0.1) [CustomClassMapper]: No setter/field for User found on class com.example.e_pharmaphar_side.ui.DrugInfo
W/Firestore: (22.0.1) [CustomClassMapper]: No setter/field for Price found on class com.example.e_pharmaphar_side.ui.DrugInfo (fields/setters are case sensitive!)
(22.0.1) [CustomClassMapper]: No setter/field for Name found on class com.example.e_pharmaphar_side.ui.DrugInfo
V/FA: Inactivity, disconnecting from the service
W/ConnectionTracker: Exception thrown while unbinding
java.lang.IllegalArgumentException: Service not registered: ls@e5d9b5c
at android.app.LoadedApk.forgetServiceDispatcher(LoadedApk.java:1562)
at android.app.ContextImpl.unbindService(ContextImpl.java:1692)
at android.content.ContextWrapper.unbindService(ContextWrapper.java:717)
at ci.f(:com.google.android.gms.dynamite_measurementdynamite@205016068@20.50.16 (100700-0):1)
at ci.d(:com.google.android.gms.dynamite_measurementdynamite@205016068@20.50.16 (100700-0):2)
at lt.E(:com.google.android.gms.dynamite_measurementdynamite@205016068@20.50.16 (100700-0):9)
at ld.a(:com.google.android.gms.dynamite_measurementdynamite@205016068@20.50.16 (100700-0):3)
at ef.run(:com.google.android.gms.dynamite_measurementdynamite@205016068@20.50.16 (100700-0):3)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:458)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at iy.run(:com.google.android.gms.dynamite_measurementdynamite@205016068@20.50.16 (100700-0):5)