the activity fragment_gallery at first was showing very well but after I added some pictures inside the RecycleView within the firebase my app started crashing even after I deleted those pictures ( data ), although the rest of my app works pretty fine but only this activity ( fragment) is causing the problem
GalleryFragment.java
package com.example.universityapp.ui.gallery;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.example.universityapp.R;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import java.util.ArrayList;
import java.util.List;
public class GalleryFragment extends Fragment {
RecyclerView convoRecycler, otherRecycler;
GalleryAdapter adapter;
DatabaseReference reference;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_gallery, container, false);
convoRecycler = view.findViewById(R.id.convoRecycler);
otherRecycler = view.findViewById(R.id.otherRecycler);
reference = FirebaseDatabase.getInstance().getReference().child("gallery");
getConvoImage();
getOtherImage();
return view;
}
private void getOtherImage() {
reference.child("Other Events").addValueEventListener(new ValueEventListener() {
List<String> imageList = new ArrayList<>();
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot snapshot: dataSnapshot.getChildren()) {
String data = (String) snapshot.getValue();
imageList.add(data);
}
adapter = new GalleryAdapter(getContext(), imageList);
otherRecycler.setLayoutManager(new GridLayoutManager(getContext(), 3));
otherRecycler.setAdapter(adapter);
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
}
});
}
private void getConvoImage() {
reference.child("Convocation").addValueEventListener(new ValueEventListener() {
List<String> imageList = new ArrayList<>();
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot snapshot: dataSnapshot.getChildren()) {
String data = (String) snapshot.getValue();
imageList.add(data);
}
adapter = new GalleryAdapter(getContext(), imageList);
convoRecycler.setLayoutManager(new GridLayoutManager(getContext(), 3));
convoRecycler.setAdapter(adapter);
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
}
});
}
}
Here is the activity that is causing the crash: fragment_gallery.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.gallery.GalleryFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/text_margin"
android:orientation="vertical">
<com.google.android.material.card.MaterialCardView
android:layout_width="match_parent"
android:layout_marginVertical="8dp"
android:layout_height="280dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Convocation"
android:layout_marginTop="@dimen/text_margin"
android:textSize="@dimen/title_size"
android:layout_gravity="center_horizontal"
android:textColor="@color/textColor"
android:fontFamily="@string/bold"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginVertical="4dp"
android:background="@color/grey"/>
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@ id/convoRecycler"/>
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
<com.google.android.material.card.MaterialCardView
android:layout_width="match_parent"
android:layout_marginVertical="8dp"
android:layout_height="280dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Others"
android:layout_marginTop="@dimen/text_margin"
android:textSize="@dimen/title_size"
android:layout_gravity="center_horizontal"
android:textColor="@color/textColor"
android:fontFamily="@string/bold"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginVertical="4dp"
android:background="@color/grey"/>
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@ id/otherRecycler"/>
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
and here is the Logcat when my app crashes out:
2022-04-20 16:35:17.834 20082-20082/? I/e.universityap: Late-enabling -Xcheck:jni
2022-04-20 16:35:17.856 20082-20082/? I/e.universityap: Unquickening 22 vdex files!
2022-04-20 16:35:17.857 20082-20082/? E/e.universityap: Unknown bits set in runtime_flags: 0x800000
2022-04-20 16:35:17.920 20082-20082/? I/ForceDarkHelper: mForceDarkOrigin true
2022-04-20 16:35:17.922 20082-20082/? I/MiuiForceDarkConfig: MiuiForceDarkConfig setConfig density:2.750000, mainRule:0, secondaryRule:0, tertiaryRule:0
2022-04-20 16:35:17.924 20082-20082/? D/NetworkSecurityConfig: No Network Security Config specified, using platform default
2022-04-20 16:35:17.925 20082-20082/? D/NetworkSecurityConfig: No Network Security Config specified, using platform default
2022-04-20 16:35:17.933 20082-20107/? E/libc: Access denied finding property "ro.vendor.pref_scale_resolution"
2022-04-20 16:35:17.934 20082-20107/? E/libc: Access denied finding property "ro.vendor.pref_scale_resolution"
2022-04-20 16:35:17.941 20082-20107/? E/libc: Access denied finding property "ro.vendor.pref_scale_resolution"
2022-04-20 16:35:17.943 20082-20107/? E/libc: Access denied finding property "ro.vendor.pref_scale_resolution"
2022-04-20 16:35:17.944 20082-20082/? I/FirebaseApp: Device unlocked: initializing all Firebase APIs for app [DEFAULT]
2022-04-20 16:35:17.944 20082-20107/? E/libc: Access denied finding property "ro.vendor.pref_scale_resolution"
2022-04-20 16:35:17.945 20082-20107/? E/ion: ioctl c0044901 failed with code -1: Invalid argument
2022-04-20 16:35:17.945 20082-20107/? D/skia: SkJpegCodec::onGetPixels
2022-04-20 16:35:17.946 20082-20107/? D/skia: stream getLength() supported, buffer addr 0x72f647a000 length 186496
2022-04-20 16:35:17.946 20082-20107/? D/skia: size 186286,phy_addr 0x43300000
2022-04-20 16:35:17.946 20082-20107/? D/skia: LoadInputStreamToIonMem va 0x72f647a000 pa 0x43300000
2022-04-20 16:35:17.947 20082-20107/? D/libjpeg-alpha-oal: SWIP_INIT
2022-04-20 16:35:17.947 20082-20107/? D/libjpeg-alpha-oal: MTXXXX_JPEG_SWIP_PROTECTION value=1
2022-04-20 16:35:17.947 20082-20107/? D/libjpeg-alpha-oal: Address(orig) = 0x73813dd258 0xedc
2022-04-20 16:35:17.947 20082-20107/? D/libjpeg-alpha-oal: Address(modified) = 0x73813dc37c
2022-04-20 16:35:17.947 20082-20107/? D/libjpeg-alpha-oal: Intermidiate 73813d8088, aff3
2022-04-20 16:35:17.948 20082-20107/? D/libjpeg-alpha-oal: SWIP_INIT return
2022-04-20 16:35:17.948 20082-20107/? D/libjpeg-alpha: Huffman Builder run in subthread
2022-04-20 16:35:17.948 20082-20107/? D/libjpeg-alpha: Tile Decoder (#thread:4, size:512 256 256 416x208, alignment:256x16)
2022-04-20 16:35:17.942 20082-20082/? W/com.example.universityapp: type=1400 audit(0.0:761825): avc: denied { search } for comm=4173796E635461736B202331 name="ppm" dev="proc" ino=4026531936 scontext=u:r:untrusted_app:s0:c43,c257,c512,c768 tcontext=u:object_r:proc_ppm:s0 tclass=dir permissive=0 app=com.example.universityapp
2022-04-20 16:35:17.946 20082-20082/? W/com.example.universityapp: type=1400 audit(0.0:761826): avc: denied { search } for comm=4173796E635461736B202331 name="ppm" dev="proc" ino=4026531936 scontext=u:r:untrusted_app:s0:c43,c257,c512,c768 tcontext=u:object_r:proc_ppm:s0 tclass=dir permissive=0 app=com.example.universityapp
2022-04-20 16:35:17.949 20082-20110/? D/libjpeg-alpha: Inconsistent progression sequence for component 0 coefficient 0
2022-04-20 16:35:17.949 20082-20112/? D/libjpeg-alpha: Inconsistent progression sequence for component 0 coefficient 0
2022-04-20 16:35:17.949 20082-20111/? D/libjpeg-alpha: Inconsistent progression sequence for component 0 coefficient 0
2022-04-20 16:35:17.950 20082-20113/? D/libjpeg-alpha: Inconsistent progression sequence for component 0 coefficient 0
2022-04-20 16:35:17.950 20082-20109/? D/libjpeg-alpha: Corrupt JPEG data: 16743 extraneous bytes before marker 0xc4
2022-04-20 16:35:17.950 20082-20114/? W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
2022-04-20 16:35:17.954 20082-20113/? D/libjpeg-alpha: Inconsistent progression sequence for component 0 coefficient 0
2022-04-20 16:35:17.955 20082-20110/? D/libjpeg-alpha: Inconsistent progression sequence for component 0 coefficient 0
2022-04-20 16:35:17.955 20082-20112/? D/libjpeg-alpha: Inconsistent progression sequence for component 0 coefficient 0
2022-04-20 16:35:17.955 20082-20111/? D/libjpeg-alpha: Inconsistent progression sequence for component 0 coefficient 0
2022-04-20 16:35:17.959 20082-20110/? D/libjpeg-alpha: Inconsistent progression sequence for component 0 coefficient 0
2022-04-20 16:35:17.959 20082-20113/? D/libjpeg-alpha: Inconsistent progression sequence for component 0 coefficient 0
2022-04-20 16:35:17.960 20082-20112/? D/libjpeg-alpha: Inconsistent progression sequence for component 0 coefficient 0
2022-04-20 16:35:17.962 20082-20111/? D/libjpeg-alpha: Inconsistent progression sequence for component 0 coefficient 0
2022-04-20 16:35:17.965 20082-20111/? D/libjpeg-alpha: Inconsistent progression sequence for component 0 coefficient 0
2022-04-20 16:35:17.965 20082-20112/? D/libjpeg-alpha: Inconsistent progression sequence for component 0 coefficient 0
2022-04-20 16:35:17.966 20082-20110/? D/libjpeg-alpha: Inconsistent progression sequence for component 0 coefficient 0
2022-04-20 16:35:17.966 20082-20113/? D/libjpeg-alpha: Inconsistent progression sequence for component 0 coefficient 0
2022-04-20 16:35:17.968 20082-20116/? W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
2022-04-20 16:35:17.971 20082-20107/? D/skia: SkJpegCodec::onGetPixels -
2022-04-20 16:35:17.971 20082-20082/? I/FirebaseInitProvider: FirebaseApp initialization successful
2022-04-20 16:35:17.972 20082-20107/? E/libc: Access denied finding property "ro.vendor.pref_scale_resolution"
2022-04-20 16:35:17.973 20082-20116/? W/GooglePlayServicesUtil: com.example.universityapp requires the Google Play Store, but it is missing.
2022-04-20 16:35:17.974 20082-20116/? W/GoogleApiManager: The service for com.google.firebase.auth.api.internal.zzeg is not available: ConnectionResult{statusCode=SERVICE_INVALID, resolution=null, message=null}
2022-04-20 16:35:17.978 20082-20082/? I/ContentProviderMonitor: PerfMonitor installContentProviders : before publish content providers
2022-04-20 16:35:17.980 20082-20107/? E/libc: Access denied finding property "ro.vendor.pref_scale_resolution"
2022-04-20 16:35:17.982 20082-20107/? E/libc: Access denied finding property "ro.vendor.pref_scale_resolution"
2022-04-20 16:35:17.989 20082-20119/? I/DynamiteModule: Considering local module com.google.android.gms.measurement.dynamite:17 and remote module com.google.android.gms.measurement.dynamite:67
2022-04-20 16:35:17.989 20082-20119/? I/DynamiteModule: Selected remote version of com.google.android.gms.measurement.dynamite, version >= 67
2022-04-20 16:35:17.990 20082-20119/? V/DynamiteModule: Dynamite loader version >= 2, using loadModule2NoCrashUtils
2022-04-20 16:35:18.027 20082-20082/? E/libc: Access denied finding property "ro.vendor.pref_scale_resolution"
2022-04-20 16:35:18.045 20082-20082/? D/View: com.example.universityapp initForcedUseForceDark: 1
2022-04-20 16:35:18.058 20082-20082/? D/DecorView[]: getWindowModeFromSystem windowmode is 1
2022-04-20 16:35:18.065 20082-20119/? V/FA: onActivityCreated
2022-04-20 16:35:18.085 20082-20082/? E/libc: Access denied finding property "ro.vendor.pref_scale_resolution"
2022-04-20 16:35:18.088 20082-20082/? E/libc: Access denied finding property "ro.vendor.pref_scale_resolution"
2022-04-20 16:35:18.097 20082-20082/? E/libc: Access denied finding property "ro.vendor.pref_scale_resolution"
2022-04-20 16:35:18.101 20082-20082/? W/e.universityap: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed)
2022-04-20 16:35:18.102 20082-20082/? W/e.universityap: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed)
2022-04-20 16:35:18.116 20082-20126/? V/FA: App measurement collection enabled
2022-04-20 16:35:18.116 20082-20126/? V/FA: App measurement enabled for app package, google app id: com.example.universityapp, 1:264695498772:android:837d69c53db8cfa6897f01
2022-04-20 16:35:18.117 20082-20126/? I/FA: App measurement initialized, version: 58022
2022-04-20 16:35:18.117 20082-20126/? I/FA: To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
2022-04-20 16:35:18.117 20082-20126/? I/FA: To enable faster debug mode event logging run:
adb shell setprop debug.firebase.analytics.app com.example.universityapp
2022-04-20 16:35:18.117 20082-20126/? D/FA: Debug-level message logging enabled
2022-04-20 16:35:18.137 20082-20082/? E/libc: Access denied finding property "ro.vendor.pref_scale_resolution"
2022-04-20 16:35:18.151 20082-20126/? V/FA: Connecting to remote service
2022-04-20 16:35:18.157 20082-20126/? V/FA: Connection attempt already in progress
2022-04-20 16:35:18.160 20082-20126/? V/FA: Connection attempt already in progress
2022-04-20 16:35:18.184 20082-20082/? E/libc: Access denied finding property "ro.vendor.pref_scale_resolution"
2022-04-20 16:35:18.232 20082-20082/? E/libc: Access denied finding property "ro.vendor.pref_scale_resolution"
2022-04-20 16:35:18.237 20082-20082/? I/chatty: uid=10299(com.example.universityapp) identical 1 line
2022-04-20 16:35:18.248 20082-20082/? E/libc: Access denied finding property "ro.vendor.pref_scale_resolution"
2022-04-20 16:35:18.260 20082-20082/? E/libc: Access denied finding property "ro.vendor.pref_scale_resolution"
2022-04-20 16:35:18.282 20082-20082/? I/chatty: uid=10299(com.example.universityapp) identical 2 lines
2022-04-20 16:35:18.305 20082-20082/? E/libc: Access denied finding property "ro.vendor.pref_scale_resolution"
2022-04-20 16:35:18.311 20082-20082/? W/ActionBarDrawerToggle: DrawerToggle may not show up because NavigationIcon is not visible. You may need to call actionbar.setDisplayHomeAsUpEnabled(true);
2022-04-20 16:35:18.324 20082-20126/? V/FA: Activity resumed, time: 751123979
2022-04-20 16:35:18.325 20082-20126/? I/FA: Tag Manager is not found and thus will not be used
2022-04-20 16:35:18.328 20082-20082/? I/SurfaceFactory: [static] sSurfaceFactory = com.mediatek.view.impl.SurfaceFactoryImpl@c51360e
2022-04-20 16:35:18.335 20082-20082/? D/ViewRootImpl[MainActivity]: hardware acceleration = true , fakeHwAccelerated = false, sRendererDisabled = false, forceHwAccelerated = false, sSystemRendererDisabled = false
2022-04-20 16:35:18.341 20082-20082/? I/InputTransport: Create ARC handle: 0xb40000728e6dd440
2022-04-20 16:35:18.342 20082-20082/? V/PhoneWindow: DecorView setVisiblity: visibility = 0, Parent = android.view.ViewRootImpl@4837228, this = DecorView@baffb41[MainActivity]
2022-04-20 16:35:18.343 20082-20082/? W/Looper: PerfMonitor looperActivity : package=com.example.universityapp/.MainActivity time=0ms latency=452ms running=0ms procState=2 ClientTransaction{ callbacks=[android.app.servertransaction.TopResumedActivityChangeItem] } historyMsgCount=4 (msgIndex=3 wall=90ms seq=3 running=71ms runnable=4ms io=2ms late=6ms h=android.app.ActivityThread$H w=110) (msgIndex=4 wall=358ms seq=4 running=325ms runnable=2ms late=94ms h=android.app.ActivityThread$H w=159)
2022-04-20 16:35:18.351 20082-20126/? V/FA: Connection attempt already in progress
2022-04-20 16:35:18.352 20082-20126/? V/FA: Connection attempt already in progress
2022-04-20 16:35:18.385 20082-20082/? E/libc: Access denied finding property "ro.vendor.pref_scale_resolution"
2022-04-20 16:35:18.387 20082-20082/? I/chatty: uid=10299(com.example.universityapp) identical 2 lines
2022-04-20 16:35:18.390 20082-20082/? E/libc: Access denied finding property "ro.vendor.pref_scale_resolution"
2022-04-20 16:35:18.394 20082-20082/? W/Glide: Failed to find GeneratedAppGlideModule. You should include an annotationProcessor compile dependency on com.github.bumptech.glide:compiler in your application and a @GlideModule annotated AppGlideModule implementation or LibraryGlideModules will be silently ignored
2022-04-20 16:35:18.463 20082-20082/? E/libc: Access denied finding property "ro.vendor.pref_scale_resolution"
2022-04-20 16:35:18.482 20082-20082/? E/libc: Access denied finding property "ro.vendor.pref_scale_resolution"
2022-04-20 16:35:18.492 20082-20082/? E/libc: Access denied finding property "ro.vendor.pref_scale_resolution"
2022-04-20 16:35:18.502 20082-20082/? E/libc: Access denied finding property "ro.vendor.pref_scale_resolution"
2022-04-20 16:35:18.512 20082-20082/? E/libc: Access denied finding property "ro.vendor.pref_scale_resolution"
2022-04-20 16:35:18.522 20082-20082/? I/chatty: uid=10299(com.example.universityapp) identical 1 line
2022-04-20 16:35:18.531 20082-20082/? E/libc: Access denied finding property "ro.vendor.pref_scale_resolution"
2022-04-20 16:35:18.559 20082-20146/? E/libc: Access denied finding property "vendor.debug.drm.logv"
2022-04-20 16:35:18.559 20082-20146/? E/libc: Access denied finding property "vendor.debug.drm.logv"
2022-04-20 16:35:18.559 20082-20146/? E/libc: Access denied finding property "vendor.debug.drm.logd"
2022-04-20 16:35:18.559 20082-20146/? E/libc: Access denied finding property "vendor.debug.drm.logv"
2022-04-20 16:35:18.565 20082-20123/? E/ion: ioctl c0044901 failed with code -1: Invalid argument
2022-04-20 16:35:18.565 20082-20146/? D/skia: SkJpegCodec::onGetPixels
2022-04-20 16:35:18.565 20082-20146/? D/libjpeg-alpha-oal: SWIP_INIT return
2022-04-20 16:35:18.569 20082-20146/? D/skia: SkJpegCodec::onGetPixels -
2022-04-20 16:35:18.588 20082-20146/? D/skia: SkJpegCodec::onGetPixels
2022-04-20 16:35:18.588 20082-20146/? D/libjpeg-alpha-oal: SWIP_INIT return
2022-04-20 16:35:18.593 20082-20146/? D/skia: SkJpegCodec::onGetPixels -
2022-04-20 16:35:18.611 20082-20082/? E/libc: Access denied finding property "ro.vendor.pref_scale_resolution"
2022-04-20 16:35:18.613 20082-20082/? E/libc: Access denied finding property "ro.vendor.pref_scale_resolution"
2022-04-20 16:35:18.625 20082-20082/? I/TetheringManager: registerTetheringEventCallback:com.example.universityapp
2022-04-20 16:35:18.635 20082-20126/? D/FA: Connected to remote service
2022-04-20 16:35:18.635 20082-20126/? V/FA: Processing queued up service tasks: 5
2022-04-20 16:35:19.739 20082-20146/? D/skia: SkJpegCodec::onGetPixels
2022-04-20 16:35:19.739 20082-20146/? D/libjpeg-alpha-oal: SWIP_INIT return
2022-04-20 16:35:19.743 20082-20146/? D/skia: SkJpegCodec::onGetPixels -
2022-04-20 16:35:21.716 20082-20082/? E/libc: Access denied finding property "ro.vendor.pref_scale_resolution"
2022-04-20 16:35:21.718 20082-20082/? I/chatty: uid=10299(com.example.universityapp) identical 1 line
2022-04-20 16:35:21.718 20082-20082/? E/libc: Access denied finding property "ro.vendor.pref_scale_resolution"
2022-04-20 16:35:21.737 20082-20146/? D/skia: SkJpegCodec::onGetPixels
2022-04-20 16:35:21.737 20082-20146/? D/libjpeg-alpha-oal: SWIP_INIT return
2022-04-20 16:35:21.753 20082-20146/? D/skia: SkJpegCodec::onGetPixels -
2022-04-20 16:35:23.678 20082-20126/? V/FA: Inactivity, disconnecting from the service
2022-04-20 16:35:23.727 20082-20146/? D/skia: SkJpegCodec::onGetPixels
2022-04-20 16:35:23.727 20082-20146/? D/libjpeg-alpha-oal: SWIP_INIT return
2022-04-20 16:35:23.731 20082-20146/? D/skia: SkJpegCodec::onGetPixels -
2022-04-20 16:35:29.245 20082-20082/? E/libc: Access denied finding property "ro.vendor.pref_scale_resolution"
2022-04-20 16:35:29.286 20082-20082/? E/RecyclerView: No adapter attached; skipping layout
2022-04-20 16:35:29.286 20082-20082/? E/RecyclerView: No adapter attached; skipping layout
2022-04-20 16:35:29.319 20082-20156/? I/System.out: [socket]:check permission begin!
2022-04-20 16:35:30.449 20082-20082/? I/ViewTarget: Glide treats LayoutParams.WRAP_CONTENT as a request for an image the size of this device's screen dimensions. If you want to load the original image and are ok with the corresponding memory cost and OOMs (depending on the input size), use override(Target.SIZE_ORIGINAL). Otherwise, use LayoutParams.MATCH_PARENT, set layout_width and layout_height to fixed dimension, or use .override() with fixed dimensions.
2022-04-20 16:35:30.459 20082-20082/? D/AndroidRuntime: Shutting down VM
2022-04-20 16:35:30.462 20082-20082/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.universityapp, PID: 20082
java.lang.ClassCastException: java.util.HashMap cannot be cast to java.lang.String
at com.example.universityapp.ui.gallery.GalleryFragment$2.onDataChange(GalleryFragment.java:85)
at com.google.firebase.database.core.ValueEventRegistration.fireEvent(ValueEventRegistration.java:75)
at com.google.firebase.database.core.view.DataEvent.fire(DataEvent.java:63)
at com.google.firebase.database.core.view.EventRaiser$1.run(EventRaiser.java:55)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:236)
at android.app.ActivityThread.main(ActivityThread.java:8049)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:620)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1011)
2022-04-20 16:35:30.467 20082-20146/? D/skia: stream getLength() not supported, use temp buffer for loading stream, buffer addr 0x72ea85c000 length 314070
2022-04-20 16:35:30.467 20082-20146/? D/skia: size 314070,phy_addr 0x43300000
2022-04-20 16:35:30.467 20082-20146/? D/skia: LoadInputStreamToIonMem va 0x72ea85c000 pa 0x43300000
2022-04-20 16:35:30.467 20082-20146/? D/libjpeg-alpha-oal: SWIP_INIT return
2022-04-20 16:35:30.468 20082-20146/? D/libjpeg-alpha-oal: SWIP_INIT return
2022-04-20 16:35:30.468 20082-20146/? D/libjpeg-alpha: Huffman Builder run in subthread
2022-04-20 16:35:30.469 20082-20146/? D/libjpeg-alpha: Tile Decoder (#thread:4, size:1024 1024 1024 1008x768, alignment:256x16)
2022-04-20 16:35:30.466 20082-20082/? W/glide-disk-cach: type=1400 audit(0.0:761827): avc: denied { search } for name="ppm" dev="proc" ino=4026531936 scontext=u:r:untrusted_app:s0:c43,c257,c512,c768 tcontext=u:object_r:proc_ppm:s0 tclass=dir permissive=0 app=com.example.universityapp
2022-04-20 16:35:30.466 20082-20082/? W/glide-disk-cach: type=1400 audit(0.0:761828): avc: denied { search } for name="ppm" dev="proc" ino=4026531936 scontext=u:r:untrusted_app:s0:c43,c257,c512,c768 tcontext=u:object_r:proc_ppm:s0 tclass=dir permissive=0 app=com.example.universityapp
2022-04-20 16:35:30.526 20082-20082/? I/Process: Sending signal. PID: 20082 SIG: 9
CodePudding user response:
Your app is crashing because a ClassCastException
is being thrown within your GalleryFragment
on line 85. According to the logging, you are attempting to cast a HashMap
to a String
, which you cannot do because it is not a child of that class. You would have to resolve that in order to prevent the crash; it does not appear to have anything to do with your fragment_gallery.xml
.
When you invoke String data = (String) snapshot.getValue();
, using (String)
means you want to basically have the return of .getValue()
to be seen as a String
. This is okay to do if the return value is a type that extends from String
, but a HashMap
does not.
Depending on your purpose, which is unclear from the question, you could either change your imageList
to be of List<HashMap>
if you know that snapshot
will always be of type HashMap
. Otherwise, if it could be String
or HashMap
, then you probably need to get the relevant value out of the HashMap
as a String
.
CodePudding user response:
Problem solved, all i neaded to do is change the line from
String data = (String) snapshot.getValue();
to
String data = (String) snapshot.getValue().toString();
I just had to add toSting() to the end of that line and my app doesn't crash anymore