0

I am making an android app with java using android studio (SDK 29). Once I go inside the search screen, all the users are displayed. But once I type in the users' nickname, they all disappear, not showing the one that I have searched.

I run the debugger to understand better what is going on and once I type the nickname in the search field, the debugger displays this message:

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 I/censapplicatio: Compiler allocated 4MB to compile void android.widget.TextView.(android.content.Context, android.util.AttributeSet, int, int) I/AssistStructure: Flattened final assist data: 5580 bytes, containing 1 windows, 23 views W/ExifInterface: Stop reading file since a wrong offset may cause an infinite loop: 0 W/ExifInterface: Stop reading file since a wrong offset may cause an infinite loop: 0 D/ViewRootImpl@7a531ea[UserProfile]: MSG_RESIZED: frame=[0,0][1080,2340] ci=[0,83][0,126] vi=[0,83][0,1003] or=1 W/Glide: Load failed for with size [131x131] class com.bumptech.glide.load.engine.GlideException: Failed to load resource I/censapplicatio: Compiler allocated 4MB to compile void android.view.ViewRootImpl.performTraversals() Disconnected from the target VM, address: 'localhost:8603', transport: 'socket'

Here is the code line where I call Glide into the adapter:

        Glide.with(mContext).load(user.getImage()).into(viewHolder.image_profile);

And here is my method SearchUsers():

private void searchUsers(String s){

    Query query = FirebaseDatabase.getInstance().getReference("Users").orderByChild("nickname")
            .startAt(s)
            .endAt(s+"\uf8ff");

    query.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
            mUsers.clear();
            for (DataSnapshot snapshot : dataSnapshot.getChildren()){
                User user = snapshot.getValue(User.class);
                mUsers.add(user);
            }

            userAdapter.notifyDataSetChanged();
        }

        @Override
        public void onCancelled(@NonNull DatabaseError databaseError) {

        }
    });
}

I checked more than 10 possible solutions but none of them worked.

I am not sure if the bug comes from the code itself or any problems related to the dependencies with Glide.

Zoe
  • 27,060
  • 21
  • 118
  • 148
HeyYou
  • 1
  • 2
  • You didn't generate the AppGlideModule. Might this will help you https://stackoverflow.com/a/46638213/10182897 – Ashish Mar 17 '20 at 12:52
  • Okay thanks, let me try that. I will keep you updated. – HeyYou Mar 17 '20 at 12:58
  • Sorry Ashish, i'm kinda new to android studio and i'm not really following what the linked answer is saying. Could you explain it in steps what i have to do? How do i generate the AppGlideModule? I saw the documentation of glide but it doesn't explain it in steps. Thank you in advance, appreciate your interest. – HeyYou Mar 17 '20 at 13:11
  • ok i'll post proper details – Ashish Mar 17 '20 at 13:12
  • just make sure you add proper glide module code – Ashish Mar 17 '20 at 13:16

1 Answers1

0

First import annotation :

repositories {
    mavenCentral()
}

dependencies {
    annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
}

Sync Project Then Create a Class

import com.bumptech.glide.annotation.GlideModule;
import com.bumptech.glide.module.AppGlideModule;

@GlideModule
public class GlideApp extends AppGlideModule {

}

and After that, I build/rebuild the project

As i can see you work with firebase store use the following glidemodule :

@GlideModule
public class MyAppGlideModule extends AppGlideModule {

    @Override
    public void registerComponents(Context context, Glide glide, Registry registry) {
        // Register FirebaseImageLoader to handle StorageReference
        registry.append(StorageReference.class, InputStream.class,
                new FirebaseImageLoader.Factory());
    }
}
Ashish
  • 6,791
  • 3
  • 26
  • 48
  • 1
    When I run the Build, once I create a Java Class inside my application following your steps, I get this error: error: duplicate class: com.example.lutescensapplication.GlideApp public final class GlideApp { It looks like i have already a glide app. I will try with the rest of your code. – HeyYou Mar 17 '20 at 13:43
  • So, apparently i had already a GlideApp class. Then i went to create the MyAppGlideModule. I imported everything but i get an error at: new FirebaseImageLoader.Factory() Cannot resolve symbol FirebaseImageLoader – HeyYou Mar 17 '20 at 13:51
  • I got it work but still, when i type a nickname in the search bar, users do not get displayed. – HeyYou Mar 17 '20 at 14:37
  • And "W/Glide: Load failed for with size [131x131] class com.bumptech.glide.load.engine.GlideException: Failed to load resource" get displayed again into the debugger once i click on the search field. – HeyYou Mar 17 '20 at 14:38
  • https://stackoverflow.com/a/55473137/10182897 please read this and post database structure – Ashish Mar 17 '20 at 14:41
  • 1
    I got the search work. I got read of: .orderByChild("nickname") .startAt(s) .endAt(s+"\uf8ff"); Then i created an if inside the for loop: if(user.getNickname().toLowerCase().contains(s.toLowerCase())){ mUsers.add(user); } else { Toast.makeText(getContext(), "No users found", Toast.LENGTH_SHORT).show(); } – HeyYou Mar 17 '20 at 15:01
  • The search now works, but Glide doesn't work. During the build i get "Note: [1] Wrote GeneratedAppGlideModule with: []" in red in the build output. And the debugger prints "W/Glide: Load failed for with size [138x138] class com.bumptech.glide.load.engine.GlideException: Failed to load resource" when i type in the search bar. I saw the answer that you posted, and everything is the same (latest verion of glide in Module:app dependecies and mavenCenter() in Project buildscript repositories). – HeyYou Mar 17 '20 at 15:23