0

残念ながら私は解決できない問題があります。だから私はあなたの助けが必要です。新しいユーザーが追加され、userActivity(KontakteActivity)が開いていると、アプリがクラッシュすることがあります。私が忘れてしまった場合は私に知らせてください問題の解決ここでFirebase RecylerviewはpopulateViewでNullPointerExceptionをスローします

するのに役立つ何かがuserActivityのコードです:ここで

import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 
import android.support.v7.widget.LinearLayoutManager; 
import android.support.v7.widget.RecyclerView; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.ImageView; 
import android.widget.LinearLayout; 
import android.widget.ProgressBar; 
import android.widget.TextView; 

import com.bumptech.glide.Glide; 
import com.bumptech.glide.load.engine.DiskCacheStrategy; 
import com.firebase.ui.database.FirebaseRecyclerAdapter; 
import com.google.firebase.database.DatabaseReference; 
import com.google.firebase.database.FirebaseDatabase; 

public class KontakteActivity extends AppCompatActivity { 

    TextView kontakt_name,kontakt_email; 
    RecyclerView recyclerView; 
    FirebaseDatabase firebaseDatabase; 
    DatabaseReference mDatabaseReference; 
    public FirebaseRecyclerAdapter<FirebaseDB_helper,Kontakte_Viewholder> mFirebaseAdapter; 
    ProgressBar progressBar; 
    LinearLayoutManager linearLayoutManager; 

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


     //DB 
     firebaseDatabase = FirebaseDatabase.getInstance(); 
     mDatabaseReference = firebaseDatabase.getReference("Users"); 
     mDatabaseReference.keepSynced(true); 

     //Views 
     progressBar = (ProgressBar)findViewById(R.id.progressBar_act_kontakte); 

     recyclerView = (RecyclerView)findViewById(R.id.recylerView_kontakte_act_kontakte); 

     linearLayoutManager = new LinearLayoutManager(KontakteActivity.this); 


     recyclerView.setLayoutManager(linearLayoutManager); 
    } 


    @Override 
    protected void onStart() { 
     super.onStart(); 

     progressBar.setVisibility(ProgressBar.VISIBLE); 


     mFirebaseAdapter = new FirebaseRecyclerAdapter<FirebaseDB_helper, Kontakte_Viewholder> 
       (FirebaseDB_helper.class, R.layout.kontakte_card_view, Kontakte_Viewholder.class, mDatabaseReference) { 


      public void populateViewHolder(final Kontakte_Viewholder viewholder , FirebaseDB_helper model, final int position) 
      { 

       progressBar.setVisibility(View.INVISIBLE); 

        viewholder.Kontakt_Name(model.getName()); 
        viewholder.Kontakt_Image(model.getImage_Url()); 
        if (model.getEmail().equals(MainActivity.User_email)) 
        { 
         viewholder.Layout_hide(); 
        }else { 
         viewholder.Kontakt_Email(model.getEmail()); 
        } 

      } 
     }; 

     mFirebaseAdapter.notifyDataSetChanged(); 

     recyclerView.setAdapter(mFirebaseAdapter); 


    } 

// /* 

    public static class Kontakte_Viewholder extends RecyclerView.ViewHolder{ 

     private final TextView kontakt_name,kontakt_email; 
     private final ImageView kontakt_image; 
     private final LinearLayout layout; 
     final LinearLayout.LayoutParams params; 

     public Kontakte_Viewholder(final View itemView) { 
      super(itemView); 

      kontakt_name=(TextView)itemView.findViewById(R.id.txt_name_kontakt_card); 
      kontakt_email=(TextView)itemView.findViewById(R.id.txtView_email_kontakt_card); 
      kontakt_image=(ImageView)itemView.findViewById(R.id.imageView_kontakt_card); 
      layout = (LinearLayout)itemView.findViewById(R.id.linearlayout_kontakt_card_view); //Probleeeeeem 
      params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);//erforderlich um ein LinearLayout anzupassen 
     } 

     private void Kontakt_Name(String name) 
     { 
      kontakt_name.setText(name); 
     } 

     private void Layout_hide() 
     { 
      params.height=0; 
      layout.setLayoutParams(params); 
     } 

     private void Kontakt_Email (String email) 
     { 
      kontakt_email.setText(email); 
     } 

     private void Kontakt_Image (String Url) 
     { 
      if (!Url.equals("Null")){ 
       Glide.with(itemView.getContext()) 
         .load(Url) 
         .crossFade() 
         .thumbnail(0.5f) 
         .placeholder(R.drawable.loading) 
         .diskCacheStrategy(DiskCacheStrategy.ALL) 
         .into(kontakt_image); 
      } 
     } 


    }//*/ 
} 

は、Android Studioの

E/AndroidRuntime: FATAL EXCEPTION: main 
    Process: com.example.zare.ma_firechat, PID: 9510 
    java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference 
     at com.example.zare.ma_firechat.KontakteActivity$Kontakte_Viewholder.Kontakt_Image(KontakteActivity.java:129) 
     at com.example.zare.ma_firechat.KontakteActivity$Kontakte_Viewholder.access$100(KontakteActivity.java:94) 
     at com.example.zare.ma_firechat.KontakteActivity$1.populateViewHolder(KontakteActivity.java:74) 
     at com.example.zare.ma_firechat.KontakteActivity$1.populateViewHolder(KontakteActivity.java:61) 
     at com.firebase.ui.database.FirebaseRecyclerAdapter.onBindViewHolder(FirebaseRecyclerAdapter.java:184) 
     at android.support.v7.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:6356) 
     at android.support.v7.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:6389) 
     at android.support.v7.widget.RecyclerView$Recycler.tryBindViewHolderByDeadline(RecyclerView.java:5335) 
     at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5598) 
     at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5440) 
     at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5436) 
     at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2224) 
     at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1551) 
     at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1511) 
     at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:595) 
     at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3583) 
     at android.support.v7.widget.RecyclerView.onMeasure(RecyclerView.java:3025) 
     at android.view.View.measure(View.java:19734) 
     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6120) 
     at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464) 
     at android.widget.LinearLayout.measureVertical(LinearLayout.java:758) 
     at android.widget.LinearLayout.onMeasure(LinearLayout.java:640) 
     at android.view.View.measure(View.java:19734) 
     at android.support.constraint.ConstraintLayout.onMeasure(ConstraintLayout.java:1028) 
     at android.view.View.measure(View.java:19734) 
     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6120) 
     at android.widget.FrameLayout.onMeasure(FrameLayout.java:185) 
     at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:139) 
     at android.view.View.measure(View.java:19734) 

のクラッシュレポートですImage of the View

+0

1人以上のユーザーがデータベースにいくつかのプロパティがないようです。 KontakteActivity.java行129に移動して、それがどのプロパティであるかを確認します。デバッガでAndroidスタジオからアプリを実行すると、その行でもアプリが破損します。 https://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-itを参照してください。 –

答えて

0

private void Kontakt_Image (String Url)の入力パラメータはnullです。 ヌルチェックが必要です。

private void Kontakt_Image (String Url) 
    { 
     if (Url!=null && !Url.equals("Null")){ 
      Glide.with(itemView.getContext()) 
        .load(Url) 
        .crossFade() 
        .thumbnail(0.5f) 
        .placeholder(R.drawable.loading) 
        .diskCacheStrategy(DiskCacheStrategy.ALL) 
        .into(kontakt_image); 
     } 
    } 
関連する問題