E/RecyclerView: No adapter attached; skipping layout (Android)

Multi tool use
Multi tool use
The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


E/RecyclerView: No adapter attached; skipping layout (Android)



I have attached my adapter to my main activity's onCreate, after loading the user data to a model class named (Users.java) and then passing this ArrayList to the adapter.I am using Firestore.
It was working earlier but then after a few tests it stopped working. App crashes as soon as main activity is loaded. Please help. Thanks in advance.



MainActivity.java


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

// To make App Bar from Action Bar (AppComp)
Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar);
setSupportActionBar(myToolbar);

mAuth = FirebaseAuth.getInstance();

mRecyclerView = findViewById(R.id.recyclerView);
mRecyclerView.setHasFixedSize(true);
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));

// Check if user is signed in (non null) and update UI accordingly.
FirebaseUser currentUser = mAuth.getCurrentUser();

if (currentUser == null) {
Intent authIntent = new Intent(MainActivity.this, SignUpActivity.class);
startActivity(authIntent);
finish();
} else {

mUsers = new ArrayList<>();
db.collection("users")
.get()
.addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
for (QueryDocumentSnapshot document : task.getResult()) {
Log.d(TAG, document.getId() + " => " + document.getData());
Users users = document.toObject(Users.class);
mUsers.add(users);
}
mAdapter = new UsersAdapter(MainActivity.this, mUsers);
mRecyclerView.setAdapter(mAdapter);
ProgressBar progressBar = (ProgressBar) findViewById(R.id.progressBar9);
progressBar.setVisibility(View.INVISIBLE);
} else {
Log.d(TAG, "Error getting documents: ", task.getException());
}
}
});
}
}



UsersAdapter.java


public class UsersAdapter extends RecyclerView.Adapter<UsersAdapter.UsersViewHolder> {

private Context mContext;
private List<Users> mUsers;

public UsersAdapter(Context context, List<Users> users) {
mContext = context;
mUsers = users;
}

@NonNull
@Override
public UsersViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View v = LayoutInflater.from(mContext).inflate(R.layout.users_card, parent, false);
return new UsersViewHolder(v);
}

@Override
public void onBindViewHolder(@NonNull UsersViewHolder holder, int position) {
Users currentUser = mUsers.get(position);
holder.textViewName.setText(currentUser.getUserName());
Picasso.get()
.load(currentUser.getUserImageUrl())
.fit()
.centerCrop()
.into(holder.imageViewPhoto);
}

@Override
public int getItemCount() {
return mUsers.size();
}

public class UsersViewHolder extends RecyclerView.ViewHolder{

public ImageView imageViewPhoto;
public TextView textViewName;

public UsersViewHolder(View itemView) {
super(itemView);

imageViewPhoto = itemView.findViewById(R.id.user_image);
textViewName = itemView.findViewById(R.id.user_name);

}
}



}



Logcat


E/RecyclerView: No adapter attached; skipping layout

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.sandeeppradhan.sailors, PID: 3286
java.lang.IllegalArgumentException: Path must not be empty.
at com.squareup.picasso.Picasso.load(Picasso.java:332)
at com.example.sandeeppradhan.sailors.UsersAdapter.onBindViewHolder(UsersAdapter.java:39)
at com.example.sandeeppradhan.sailors.UsersAdapter.onBindViewHolder(UsersAdapter.java:17)





RecyclerView: No adapter attached; skipping layout is just a warning, saying you don't have an adapter setup yet. That's probably before your data is fetched from your server. What is the actual crash? Can you post your stacktrace?
– Advice-Dog
yesterday


RecyclerView: No adapter attached; skipping layout





@Advice-Dog my Logcat posted. Please check. Thanks
– Sandeep Pradhan
yesterday







@Advice-Dog Yes that was just a warning, I got the problem, the imageUrl is not getting saved for some users and that is why app is crashing. I will try to figure that out, if you have any suggestion please help, Logcat posted. Please check. Thanks
– Sandeep Pradhan
yesterday




1 Answer
1



try doing this


mRecyclerView = findViewById(R.id.recyclerView);
mRecyclerView.setHasFixedSize(true);
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));



in


mUsers = new ArrayList<>();
db.collection("users")
.get()
.addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
for (QueryDocumentSnapshot document : task.getResult()) {
Log.d(TAG, document.getId() + " => " + document.getData());
Users users = document.toObject(Users.class);
mUsers.add(users);
}
//HERE
mAdapter = new UsersAdapter(MainActivity.this, mUsers);
mRecyclerView.setAdapter(mAdapter);
ProgressBar progressBar = (ProgressBar) findViewById(R.id.progressBar9);
progressBar.setVisibility(View.INVISIBLE);
} else {
Log.d(TAG, "Error getting documents: ", task.getException());
}
}
});
}



Also make sure that your string with the url of the image isn't empty, in that case if some users haven't a imgurl just do a try catch in onBindViewHolder our just check of the image is empty with an if





Yes I got the answer, the problem was related to no image url.
– Sandeep Pradhan
yesterday






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

s44blVsR1sZFcICZtqsM,CH,fzj r7uQMy Sfv,J
4 QYWsMmQ,cI9ppYq2QNnJAKTsy O1t29k nA bz2Ytr6rtTq9C56YNR7o2

Popular posts from this blog

Keycloak server returning user_not_found error when user is already imported with LDAP

PHP parse/syntax errors; and how to solve them?

Using generate_series in ecto and passing a value