1. Are you ready for the Galaxy S20? Here is everything we know so far!

Getting a NullPointerException: boolean...on a null object reference

Discussion in 'Android Development' started by Seran, Jun 5, 2019.

  1. Seran

    Seran Lurker
    Thread Starter

    Dear Community,

    finally found a promising forum for android. I apologize, if I post this one here wrong. My problem is, that I am getting a
    I am also watching a tutorial to learn. When I implemented a "Delete your message in chat" function. The tutorial showed two versions. One, where you delete the message without leaving a text behind and second, where you leave a "Message deleted" text. I ran two tests with each version seperately, because of the tutorial ), they worked fine ) I liked the second version, so I've deleted the code for the first version ( only one line and the code just deletes message instead of replacing it ) but when I access the Chat Window/Layout it crashes, yesterday it worked fine. In the ChatActivity the "getReceiver" may produce a NullPointerException, it says. I really need help, because I cannot solve it.


    Code (Java):
    1. package com.example.networkusercommunication;
    2.  
    3. import android.content.Intent;
    4. import android.provider.ContactsContract;
    5. import android.service.autofill.Dataset;
    6. import android.support.annotation.NonNull;
    7. import android.support.v7.app.AppCompatActivity;
    8. import android.os.Bundle;
    9. import android.support.v7.widget.LinearLayoutManager;
    10. import android.support.v7.widget.RecyclerView;
    11. import android.support.v7.widget.Toolbar;
    12. import android.text.Editable;
    13. import android.text.TextUtils;
    14. import android.text.TextWatcher;
    15. import android.text.format.DateFormat;
    16. import android.view.Menu;
    17. import android.view.MenuItem;
    18. import android.view.View;
    19. import android.widget.EditText;
    20. import android.widget.ImageButton;
    21. import android.widget.ImageView;
    22. import android.widget.LinearLayout;
    23. import android.widget.TextView;
    24. import android.widget.Toast;
    25.  
    26. import com.example.networkusercommunication.adapter.AdapterChat;
    27. import com.example.networkusercommunication.models.ModelChat;
    28. import com.google.firebase.auth.FirebaseAuth;
    29. import com.google.firebase.auth.FirebaseUser;
    30. import com.google.firebase.database.DataSnapshot;
    31. import com.google.firebase.database.DatabaseError;
    32. import com.google.firebase.database.DatabaseReference;
    33. import com.google.firebase.database.FirebaseDatabase;
    34. import com.google.firebase.database.Query;
    35. import com.google.firebase.database.ValueEventListener;
    36. import com.squareup.picasso.Picasso;
    37.  
    38. import java.util.ArrayList;
    39. import java.util.Calendar;
    40. import java.util.HashMap;
    41. import java.util.List;
    42. import java.util.Locale;
    43. import java.util.Objects;
    44.  
    45. public class ChatActivity extends AppCompatActivity {
    46.  
    47.     // views from xml
    48.     Toolbar toolbar;
    49.     RecyclerView recyclerView;
    50.     ImageView profileIv;
    51.     TextView nameTv, userStatusTv;
    52.     EditText messageEt;
    53.     ImageButton sendBtn;
    54.  
    55.     //firebase auth
    56.     FirebaseAuth firebaseAuth;
    57.  
    58.     FirebaseDatabase firebaseDatabase;
    59.     DatabaseReference usersDbRef;
    60.  
    61.     // for checking if user has seen message or not
    62.     ValueEventListener seenListener;
    63.     DatabaseReference userRefForSeen;
    64.  
    65.     List<ModelChat> chatList;
    66.     AdapterChat adapterChat;
    67.  
    68.     String hisUid;
    69.     String myUid;
    70.     String hisImage;
    71.  
    72.  
    73.     @Override
    74.     protected void onCreate(Bundle savedInstanceState) {
    75.         super.onCreate(savedInstanceState);
    76.         setContentView(R.layout.activity_chat);
    77.  
    78.         // init views
    79.         Toolbar toolbar = findViewById(R.id.toolbar);
    80.         setSupportActionBar(toolbar);
    81.         toolbar.setTitle("");
    82.         recyclerView = findViewById(R.id.chat_recyclerView);
    83.         profileIv = findViewById(R.id.profileIv);
    84.         nameTv = findViewById(R.id.nameTv);
    85.         userStatusTv = findViewById(R.id.userStatusTv);
    86.         messageEt = findViewById(R.id.messageEt);
    87.         sendBtn = findViewById(R.id.sendBtn);
    88.  
    89.         // Layout ( LinearLayout ) for RecyclerView
    90.         LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
    91.         linearLayoutManager.setStackFromEnd(true);
    92.  
    93.         // recyclerview properties
    94.         recyclerView.setHasFixedSize(true);
    95.         recyclerView.setLayoutManager(linearLayoutManager);
    96.  
    97.         /* On clicking user from users list we have passed that user's UID using intent. So get that uid here to get the profile picture,
    98.          * name and start chat with user */
    99.  
    100.         Intent intent = getIntent();
    101.         hisUid = intent.getStringExtra("hisUid");
    102.  
    103.         // firebase auth instance
    104.         firebaseAuth = FirebaseAuth.getInstance();
    105.  
    106.         firebaseDatabase = FirebaseDatabase.getInstance();
    107.         usersDbRef = firebaseDatabase.getReference("Users");
    108.  
    109.         // search user to get that user's info
    110.         Query userQuery = usersDbRef.orderByChild("uid").equalTo(hisUid);
    111.  
    112.         // get user picture and name
    113.         userQuery.addValueEventListener(new ValueEventListener() {
    114.             @Override
    115.             public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
    116.                 // check until required info is received
    117.                 for (DataSnapshot ds : dataSnapshot.getChildren()) {
    118.                     // get data
    119.                     String name = "" + ds.child("name").getValue();
    120.                     hisImage = "" + ds.child("image").getValue();
    121.                     String typingStatus = "" + ds.child("typingTo").getValue();
    122.  
    123.                     // check typing status
    124.                     if (typingStatus.equals(myUid)) {
    125.                         userStatusTv.setText("schreibt...");
    126.                     } else {
    127.  
    128.                         // get value of onlineStatus
    129.                         String onlineStatus = "" + ds.child("onlineStatus").getValue();
    130.                         if (onlineStatus.equals("online")) {
    131.                             userStatusTv.setText(onlineStatus);
    132.                         } else {
    133.                             // convert timestamp to proper time date
    134.                             // convert time stamp to dd/mm/yyyy hh:mm am/pm
    135.                             // Es gibt verschiedene Zeitstellungen ( auch Deutschland bzw. restliche Welt )
    136.                             Calendar cal = Calendar.getInstance(Locale.ENGLISH);
    137.                             cal.setTimeInMillis(Long.parseLong(onlineStatus));
    138.                             String dateTime = DateFormat.format("dd/MM/yyyy hh:mm aa", cal).toString();
    139.                             userStatusTv.setText("Zuletzt online um: " + dateTime);
    140.                         }
    141.  
    142.                     }
    143.  
    144.                     // set data
    145.                     nameTv.setText(name);
    146.  
    147.                     try {
    148.                         // image received, set it to imageview in toolbar
    149.                         Picasso.get().load(hisImage).placeholder(R.drawable.ic_default_img_white).into(profileIv);
    150.  
    151.                     } catch (Exception e) {
    152.                         // there is exception getting picture, set default picture
    153.                         Picasso.get().load(R.drawable.ic_default_img_white).into(profileIv);
    154.  
    155.                     }
    156.  
    157.                 }
    158.             }
    159.  
    160.             @Override
    161.             public void onCancelled(@NonNull DatabaseError databaseError) {
    162.  
    163.             }
    164.         });
    165.  
    166.         // click button to send message
    167.         sendBtn.setOnClickListener(new View.OnClickListener() {
    168.             @Override
    169.             public void onClick(View v) {
    170.                 // get text from edit text
    171.                 String message = messageEt.getText().toString().trim();
    172.  
    173.                 // check if text is empty or not
    174.                 if (TextUtils.isEmpty(message)) {
    175.                     // text empty
    176.                     Toast.makeText(ChatActivity.this, "Leere Nachricht kann nicht versenden werden", Toast.LENGTH_SHORT).show();
    177.  
    178.                 } else {
    179.                     // text not empty
    180.                     sendMessage(message);
    181.  
    182.                 }
    183.  
    184.             }
    185.         });
    186.  
    187.         // check edit text change listener
    188.         messageEt.addTextChangedListener(new TextWatcher() {
    189.             @Override
    190.             public void beforeTextChanged(CharSequence s, int start, int count, int after) {
    191.  
    192.             }
    193.  
    194.             @Override
    195.             public void onTextChanged(CharSequence s, int start, int before, int count) {
    196.                 if (s.toString().trim().length() == 0 ) {
    197.                     checkTypingStatus("noOne");
    198.                 } else {
    199.                     checkTypingStatus(hisUid); // uid of receiver
    200.                 }
    201.             }
    202.  
    203.             @Override
    204.             public void afterTextChanged(Editable s) {
    205.  
    206.             }
    207.         });
    208.  
    209.         readMessages();
    210.  
    211.         seenMessage();
    212.  
    213.     }
    214.  
    215.     private void seenMessage() {
    216.         userRefForSeen = FirebaseDatabase.getInstance().getReference("Chats");
    217.         seenListener = userRefForSeen.addValueEventListener(new ValueEventListener() {
    218.             @Override
    219.             public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
    220.                 for (DataSnapshot ds : dataSnapshot.getChildren()) {
    221.                     ModelChat chat = ds.getValue(ModelChat.class);
    222.  
    223.                     if ( chat.getReceiver().equals(myUid) && chat.getSender().equals(hisUid)) {
    224.  
    225.                         HashMap<String, Object> hasSeenHashMap = new HashMap<>();
    226.                         hasSeenHashMap.put("isSeen", true);
    227.                         ds.getRef().updateChildren(hasSeenHashMap);
    228.                     }
    229.                 }
    230.             }
    231.  
    232.             @Override
    233.             public void onCancelled(@NonNull DatabaseError databaseError) {
    234.  
    235.             }
    236.         });
    237.     }
    238.  
    239.     private void readMessages() {
    240.         chatList = new ArrayList<>();
    241.         DatabaseReference dbRef = FirebaseDatabase.getInstance().getReference("Chats");
    242.         dbRef.addValueEventListener(new ValueEventListener() {
    243.             @Override
    244.             public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
    245.                 chatList.clear();
    246.                 for (DataSnapshot ds : dataSnapshot.getChildren()) {
    247.                     ModelChat chat = ds.getValue(ModelChat.class);
    248.                     if (chat.getReceiver().equals(myUid) ||
    249.                             (chat.getReceiver().equals(hisUid) && chat.getSender().equals(myUid))) {
    250.                         chatList.add(chat);
    251.                     }
    252.  
    253.                     // adapter
    254.                     adapterChat = new AdapterChat(ChatActivity.this, chatList, hisImage);
    255.                     adapterChat.notifyDataSetChanged();
    256.  
    257.                     // set adapter to recyclerview
    258.                     recyclerView.setAdapter(adapterChat);
    259.                 }
    260.             }
    261.  
    262.             @Override
    263.             public void onCancelled(@NonNull DatabaseError databaseError) {
    264.  
    265.             }
    266.         });
    267.     }
    268.  
    269.     private void sendMessage(String message) {
    270.  
    271.         /* "Chats" node will be created, that will contain all chats. Whenever user
    272.          * sends message it will create a new child in "Chats" node and that child
    273.          * will contain the following key values.
    274.          * sender: UID of sender
    275.          * receiver: UID of receiver
    276.          * message: the actual message
    277.          */
    278.  
    279.         DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReference();
    280.  
    281.         String timestamp = String.valueOf(System.currentTimeMillis());
    282.  
    283.         HashMap<String, Object> hashMap = new HashMap<>();
    284.         hashMap.put("sender", myUid);
    285.         hashMap.put("receiver", hisUid);
    286.         hashMap.put("message", message);
    287.         hashMap.put("timestamp", timestamp);
    288.         hashMap.put("isSeen", false);
    289.         databaseReference.child("Chats").push().setValue(hashMap);
    290.  
    291.         // reset edittext after sending message
    292.         messageEt.setText("");
    293.  
    294.  
    295.     }
    296.  
    297.     private void checkUserStatus() {
    298.  
    299.         // get current user
    300.         FirebaseUser user = firebaseAuth.getCurrentUser();
    301.         if (user != null) {
    302.             // user is signed in stay here
    303.             //set email of logged in user
    304.             //mProfileTv.setText(user.getEmail());
    305.             myUid = user.getUid(); // currently signed in user's uid
    306.  
    307.         } else {
    308.             // user not signed in, go to main activity
    309.             startActivity(new Intent(this, MainActivity.class));
    310.             finish();
    311.         }
    312.     }
    313.  
    314.     private void checkOnlineStatus(String status) {
    315.         DatabaseReference dbRef = FirebaseDatabase.getInstance().getReference("Users").child(myUid);
    316.         HashMap<String, Object> hashMap = new HashMap<>();
    317.         hashMap.put("onlineStatus", status);
    318.  
    319.         // update value of onlineStatus of current user
    320.         dbRef.updateChildren(hashMap);
    321.     }
    322.  
    323.     private void checkTypingStatus(String typing) {
    324.         DatabaseReference dbRef = FirebaseDatabase.getInstance().getReference("Users").child(myUid);
    325.         HashMap<String, Object> hashMap = new HashMap<>();
    326.         hashMap.put("typingTo", typing);
    327.  
    328.         // update value of onlineStatus of current user
    329.         dbRef.updateChildren(hashMap);
    330.     }
    331.  
    332.     @Override
    333.     protected void onStart() {
    334.         checkUserStatus();
    335.  
    336.         // set online
    337.         checkOnlineStatus("online");
    338.         super.onStart();
    339.     }
    340.  
    341.     @Override
    342.     protected void onPause() {
    343.         super.onPause();
    344.         // get timestamp
    345.         String timestamp = String.valueOf(System.currentTimeMillis());
    346.         // set offline with last seen time stamp
    347.         checkOnlineStatus(timestamp);
    348.         checkTypingStatus("noOne");
    349.         userRefForSeen.removeEventListener(seenListener);
    350.     }
    351.  
    352.     @Override
    353.     protected void onResume() {
    354.  
    355.         // set online
    356.         checkOnlineStatus("online");
    357.         super.onResume();
    358.     }
    359.  
    360.     @Override
    361.     public boolean onCreateOptionsMenu(Menu menu) {
    362.         getMenuInflater().inflate(R.menu.menu_main, menu);
    363.         // hide searchview, as we don't need it here
    364.         menu.findItem(R.id.action_search).setVisible(false);
    365.         return super.onCreateOptionsMenu(menu);
    366.     }
    367.  
    368.     @Override
    369.     public boolean onOptionsItemSelected(MenuItem item) {
    370.         int id = item.getItemId();
    371.         if (id == R.id.action_logout) {
    372.             firebaseAuth.signOut();
    373.             checkUserStatus();
    374.         }
    375.  
    376.         return super.onOptionsItemSelected(item);
    377.     }
    378. }
    379.  
    Code (Java):
    1. package com.example.networkusercommunication.models;
    2.  
    3. public class ModelChat {
    4.  
    5.     String message, receiver, sender, timestamp;
    6.     boolean isSeen;
    7.  
    8.     public ModelChat() {
    9.     }
    10.  
    11.     public ModelChat(String message, String receiver, String sender, String timestamp, boolean isSeen) {
    12.         this.message = message;
    13.         this.receiver = receiver;
    14.         this.sender = sender;
    15.         this.timestamp = timestamp;
    16.         this.isSeen = isSeen;
    17.     }
    18.  
    19.     public String getMessage() {
    20.         return message;
    21.     }
    22.  
    23.     public void setMessage(String message) {
    24.         this.message = message;
    25.     }
    26.  
    27.     public String getReceiver() {
    28.         return receiver;
    29.     }
    30.  
    31.     public void setReceiver(String receiver) {
    32.         this.receiver = receiver;
    33.     }
    34.  
    35.     public String getSender() {
    36.         return sender;
    37.     }
    38.  
    39.     public void setSender(String sender) {
    40.         this.sender = sender;
    41.     }
    42.  
    43.     public String getTimestamp() {
    44.         return timestamp;
    45.     }
    46.  
    47.     public void setTimestamp(String timestamp) {
    48.         this.timestamp = timestamp;
    49.     }
    50.  
    51.     public boolean isSeen() {
    52.         return isSeen;
    53.     }
    54.  
    55.     public void setSeen(boolean seen) {
    56.         isSeen = seen;
    57.     }
    58. }
    59.  
    Code (Java):
    1. package com.example.networkusercommunication.adapter;
    2.  
    3. import android.app.AlertDialog;
    4. import android.content.ContentValues;
    5. import android.content.Context;
    6. import android.content.DialogInterface;
    7. import android.provider.ContactsContract;
    8. import android.support.annotation.NonNull;
    9. import android.support.v7.widget.RecyclerView;
    10. import android.text.format.DateFormat;
    11. import android.view.LayoutInflater;
    12. import android.view.View;
    13. import android.view.ViewGroup;
    14. import android.widget.ImageButton;
    15. import android.widget.ImageView;
    16. import android.widget.LinearLayout;
    17. import android.widget.TextView;
    18. import android.widget.Toast;
    19.  
    20. import com.example.networkusercommunication.R;
    21. import com.example.networkusercommunication.models.ModelChat;
    22. import com.google.firebase.auth.FirebaseAuth;
    23. import com.google.firebase.auth.FirebaseUser;
    24. import com.google.firebase.database.DataSnapshot;
    25. import com.google.firebase.database.DatabaseError;
    26. import com.google.firebase.database.DatabaseReference;
    27. import com.google.firebase.database.FirebaseDatabase;
    28. import com.google.firebase.database.Query;
    29. import com.google.firebase.database.ValueEventListener;
    30. import com.squareup.picasso.Picasso;
    31.  
    32. import java.util.Calendar;
    33. import java.util.HashMap;
    34. import java.util.List;
    35. import java.util.Locale;
    36.  
    37. public class AdapterChat extends RecyclerView.Adapter<AdapterChat.MyHolder> {
    38.  
    39.     private static final int MSG_TYPE_LEFT = 0;
    40.     private static final int MSG_TYPE_RIGHT = 1;
    41.     Context context;
    42.     List<ModelChat> chatList;
    43.     String imageUrl;
    44.  
    45.     FirebaseUser fUser;
    46.  
    47.     public AdapterChat(Context context, List<ModelChat> chatList, String imageUrl) {
    48.         this.context = context;
    49.         this.chatList = chatList;
    50.         this.imageUrl = imageUrl;
    51.     }
    52.  
    53.     @NonNull
    54.     @Override
    55.     public MyHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
    56.         // inflate layouts: row_chat_left.xml for receiver, row_chat_right.xml for sender
    57.         if (i == MSG_TYPE_RIGHT) {
    58.             View view = LayoutInflater.from(context).inflate(R.layout.row_chat_right, viewGroup, false);
    59.             return new MyHolder(view);
    60.         } else {
    61.             View view = LayoutInflater.from(context).inflate(R.layout.row_chat_left, viewGroup, false);
    62.             return new MyHolder(view);
    63.         }
    64.  
    65.     }
    66.  
    67.     @Override
    68.     public void onBindViewHolder(@NonNull MyHolder myHolder, final int i) {
    69.  
    70.         // get data
    71.         String message = chatList.get(i).getMessage();
    72.         String timeStamp = chatList.get(i).getTimestamp();
    73.  
    74.         // convert time stamp to dd/mm/yyyy hh:mm am/pm
    75.         // Es gibt verschiedene Zeitstellungen ( auch Deutschland bzw. restliche Welt )
    76.         Calendar cal = Calendar.getInstance(Locale.ENGLISH);
    77.         cal.setTimeInMillis(Long.parseLong(timeStamp));
    78.         String dateTime = DateFormat.format("dd/MM/yyyy hh:mm aa", cal).toString();
    79.  
    80.         // set data
    81.         myHolder.messageTv.setText(message);
    82.         myHolder.timeTv.setText(dateTime);
    83.         try {
    84.             Picasso.get().load(imageUrl).into(myHolder.profileIv);
    85.         } catch (Exception e) {
    86.  
    87.         }
    88.  
    89.         // click to show delete dialog
    90.         myHolder.messageLAyout.setOnClickListener(new View.OnClickListener() {
    91.             @Override
    92.             public void onClick(View v) {
    93.                 // show delete message confirm dialog
    94.                 AlertDialog.Builder builder = new AlertDialog.Builder(context);
    95.                 builder.setTitle("Delete");
    96.                 builder.setMessage("Are you sure to delete this message?");
    97.                 // delete button
    98.                 builder.setPositiveButton("Delete", new DialogInterface.OnClickListener() {
    99.                     @Override
    100.                     public void onClick(DialogInterface dialog, int which) {
    101.                         deleteMessage(i);
    102.                     }
    103.                 });
    104.  
    105.                 // cancel delete button
    106.                 builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
    107.                     @Override
    108.                     public void onClick(DialogInterface dialog, int which) {
    109.                         // dismiss dialog
    110.                         dialog.dismiss();
    111.                     }
    112.                 });
    113.  
    114.                 // create and show dialog
    115.                 builder.create().show();
    116.             }
    117.         });
    118.  
    119.         // set seen/delivered status of message
    120.         if (i == chatList.size() - 1) {
    121.             if (chatList.get(i).isSeen()) {
    122.                 myHolder.isSeenTv.setText("Gesehen");
    123.             } else {
    124.                 myHolder.isSeenTv.setText("Versendet");
    125.             }
    126.         } else {
    127.             myHolder.isSeenTv.setVisibility(View.GONE);
    128.         }
    129.     }
    130.  
    131.     private void deleteMessage(int position) {
    132.  
    133.         final FirebaseUser myUID = FirebaseAuth.getInstance().getCurrentUser();
    134.  
    135.         String msgTimeStamp = chatList.get(position).getTimestamp();
    136.         DatabaseReference dbRef = FirebaseDatabase.getInstance().getReference("Chats");
    137.         Query query = dbRef.orderByChild("timestamp").equalTo(msgTimeStamp);
    138.         query.addListenerForSingleValueEvent(new ValueEventListener() {
    139.             @Override
    140.             public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
    141.                 for (DataSnapshot ds:dataSnapshot.getChildren()) {
    142.  
    143.                     if (ds.child("sender").getValue().equals(myUID)) {
    144.  
    145.                         // Set value of message in "This message was deleted"
    146.                         HashMap<String, Object > hashMap = new HashMap<>();
    147.                         hashMap.put("message", "This message was deleted");
    148.                         ds.getRef().updateChildren(hashMap);
    149.  
    150.                         Toast.makeText(context, "message deleted", Toast.LENGTH_SHORT).show();
    151.  
    152.                     } else  {
    153.                         Toast.makeText(context, "Only your messages can be deleted", Toast.LENGTH_SHORT).show();
    154.                     }
    155.  
    156.                 }
    157.             }
    158.  
    159.             @Override
    160.             public void onCancelled(@NonNull DatabaseError databaseError) {
    161.  
    162.             }
    163.         });
    164.  
    165.  
    166.  
    167.  
    168.     }
    169.  
    170.  
    171.     @Override
    172.     public int getItemCount() {
    173.         return chatList.size();
    174.     }
    175.  
    176.     @Override
    177.     public int getItemViewType(int position) {
    178.         // get currently signed in user
    179.         fUser = FirebaseAuth.getInstance().getCurrentUser();
    180.         if (chatList.get(position).getSender().equals(fUser.getUid())) {
    181.             return MSG_TYPE_RIGHT;
    182.         } else {
    183.             return MSG_TYPE_LEFT;
    184.         }
    185.     }
    186.  
    187.     // view holder class
    188.     class MyHolder extends RecyclerView.ViewHolder {
    189.  
    190.         // views
    191.         ImageView profileIv;
    192.         TextView messageTv, timeTv, isSeenTv;
    193.         LinearLayout messageLAyout; // for click listener to show delete
    194.  
    195.  
    196.         public MyHolder(@NonNull View itemView) {
    197.             super(itemView);
    198.  
    199.             // init views
    200.             profileIv = itemView.findViewById(R.id.profileIv);
    201.             messageTv = itemView.findViewById(R.id.messageTv);
    202.             timeTv = itemView.findViewById(R.id.timeTv);
    203.             isSeenTv = itemView.findViewById(R.id.isSeenTv);
    204.             messageLAyout = itemView.findViewById(R.id.messageLayout);
    205.  
    206.  
    207.         }
    208.     }
    209. }
    210.  
     


    #1 Seran, Jun 5, 2019
    Last edited: Jun 5, 2019
  2. 23tony

    23tony Well-Known Member

    I don't see anywhere that you're calling the ModelChat constructor with a receiver:
    Code (Text):
    1.     public ModelChat(String message, String receiver, String sender, String timestamp, boolean isSeen) {
    2.         this.message = message;
    3.         this.receiver = receiver;
    4.         this.sender = sender;
    5.         this.timestamp = timestamp;
    6.         this.isSeen = isSeen;
    7.     }
    It looks to me like receiver is never set, so getReceiver is returning a null object.
     
    scary alien likes this.
Loading...

Share This Page

Loading...