在显示Firebase Recyclerview和应用程序崩溃时,在发布的应用程序版本中出现“ java.lang.NullPointerException:println需要消息”错误。我在应用程序的调试版本中没有出现任何此类错误,firebase recyclerview正常运行。
我也试图在发行版中显示Firebase recyclerview。
Query query = FirebaseDatabase.getInstance()
.getReference()
.child("userScore")
.orderByChild("userScore")
.limitToLast(100);
FirebaseRecyclerOptions<UserScoreModel> options =
new FirebaseRecyclerOptions.Builder<UserScoreModel>()
.setQuery(query, UserScoreModel.class)
.build();
adapter = new FirebaseRecyclerAdapter<UserScoreModel, ScoreViewHolder>(options) {
@Override
public ScoreViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
View view = LayoutInflater.from(viewGroup.getContext())
.inflate(R.layout.item_score, viewGroup, false);
return new ScoreViewHolder(view);
}
@Override
public UserScoreModel getItem(int position){
return super.getItem(getItemCount()-position-1);
}
@Override
protected void onBindViewHolder(ScoreViewHolder scoreViewHolder, int i, final UserScoreModel userScoreModel) {
progDialog.dismiss();
String userName = userScoreModel.getUserName();
String score = String.valueOf(userScoreModel.getUserScore());
userImage = storageRef.child("UserImage/" + userScoreModel.getUid() + userScoreModel.getProfileUrl() + ".jpeg");
Log.w("username",userName);
Log.w("score",score);
if(i+1==1){
name2.setText(userName);
String mystring = getResources().getString(R.string.Rs);
String resultStr = mystring + " " +score;
score2.setText(resultStr);
GlideApp.with(getApplicationContext()).load(userImage).override(200, 200)
.circleCrop().placeholder(getResources().getDrawable(R.drawable.boy1)).into(img2);
}
if(i+1==2){
name1.setText(userName);
String mystring = getResources().getString(R.string.Rs);
String resultStr = mystring + " " +score;
score1.setText(resultStr);
GlideApp.with(getApplicationContext()).load(userImage).override(200, 200)
.circleCrop().placeholder(getResources().getDrawable(R.drawable.boy1)).into(img1);
}
if(i+1==3){
name3.setText(userName);
String mystring = getResources().getString(R.string.Rs);
String resultStr = mystring + " " +score;
score3.setText(resultStr);
GlideApp.with(getApplicationContext()).load(userImage).override(200, 200)
.circleCrop().placeholder(getResources().getDrawable(R.drawable.boy1)).into(img3);
}
if (i+1<=3){
scoreViewHolder.itemLinear.setVisibility(View.GONE);
scoreViewHolder.itemLinear.setLayoutParams(new RecyclerView.LayoutParams(0, 0));
}
if (i+1>3){
String mystring = getResources().getString(R.string.Rs);
String resultStr = mystring + " " +score;
scoreViewHolder.score.setText(resultStr);
scoreViewHolder.nameOfPlayer.setText(userName);
scoreViewHolder.rank.setText(String.valueOf(i+1));
GlideApp.with(getApplicationContext()).load(userImage).override(200, 200)
.circleCrop().placeholder(getResources().getDrawable(R.drawable.boy1)).into(scoreViewHolder.userImage);
}
userId = userScoreModel.getUid();
if (userId.equals(uid)){
String mystring = getResources().getString(R.string.Rs);
String resultStr = mystring + " " +score;
GlideApp.with(getApplicationContext()).load(userImage).override(200, 200)
.circleCrop().placeholder(getResources().getDrawable(R.drawable.boy1)).into(myImage);
myRank.setText(String.valueOf(i+1));
myName.setText(userName);
myScore.setText(resultStr);
}
}
};