I keep coming across this issue, I'm trying to show the date the message has been posted in a messaging application and I keep getting this error and the application keeps crashing.
String message = chatList.get(position).getMessage();
String timeStamp = chatList.get(position).getTimestamp();
Calendar cal = Calendar.getInstance(Locale.ENGLISH);
cal.setTimeInMillis(Long.parseLong(timeStamp));
String dateTime = DateFormat.format("dd/MM/yyyy hh:mm aa", cal).toString();
holder.messageTv.setText(message);
holder.timeTv.setText(dateTime);
This is the logcat error I receive:
2020-09-02 22:10:08.411 13445-13445/com.x00122898.meetupproject E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.x00122898.meetupproject, PID: 13445
java.lang.NumberFormatException: For input string: "null"
at java.lang.Long.parseLong(Long.java:594)
at java.lang.Long.parseLong(Long.java:636)
at com.x00122898.meetupproject.ChatActivity$1.onDataChange(ChatActivity.java:107)
at com.google.firebase.database.core.ValueEventRegistration.fireEvent(com.google.firebase:firebase-database@@16.0.4:75)
at com.google.firebase.database.core.view.DataEvent.fire(com.google.firebase:firebase-database@@16.0.4:63)
at com.google.firebase.database.core.view.EventRaiser$1.run(com.google.firebase:firebase-database@@16.0.4:55)
at android.os.Handler.handleCallback(Handler.java:888)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:213)
at android.app.ActivityThread.main(ActivityThread.java:8178)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1101)
2020-09-02 22:10:08.422 13445-13445/com.x00122898.meetupproject I/Process: Sending signal. PID: 13445 SIG: 9
Any help would be greatly appreciated ~