-1

My application runs fine(but still only displays 4 toggle buttons and FAB button) on the emulator until I enter this code:

 val newThought = Thought(
                name, timestamp, thoughtText, numberLikes?.toInt(),
                numberComments?.toInt(), documentId
            )

   thoughts.add(newThought)

It seems that the above code causes the app to crash.

I have tested each block of code on the emulator and it seems that only this part:

 val newThought = Thought(
                    name, timestamp, thoughtText, numberLikes?.toInt(),
                    numberComments?.toInt(), documentId
                )

       thoughts.add(newThought)

causes my app to crash.

My code: package swiftstartechnology.co.myapplication

import android.content.Intent
import android.os.Bundle
import android.util.Log
import com.google.android.material.snackbar.Snackbar
import androidx.appcompat.app.AppCompatActivity
import android.view.Menu
import android.view.MenuItem
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import com.google.firebase.firestore.FieldValue
import com.google.fire

This is the error I get:

09/26 20:32:59: Launching 'app' on Pixel XL API 29.
$ adb shell am start -n "swiftstartechnology.co.myapplication/swiftstartechnology.co.myapplication.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Waiting for process to come online...
Connected to process 6953 on device 'Pixel_XL_API_29 [emulator-5554]'.
Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page.
V/FA: Registered activity lifecycle callback
I/FirebaseInitProvider: FirebaseApp initialization successful
D/libEGL: Emulator has host GPU support, qemu.gles is set to 1.
W/libc: Unable to set property "qemu.gles" to "1": connection failed; errno=13 (Permission denied)
D/libEGL: loaded /vendor/lib/egl/libEGL_emulation.so
D/libEGL: loaded /vendor/lib/egl/libGLESv1_CM_emulation.so
D/libEGL: loaded /vendor/lib/egl/libGLESv2_emulation.so
W/RenderThread: type=1400 audit(0.0:58): avc: denied { write } for name="property_service" dev="tmpfs" ino=6623 scontext=u:r:untrusted_app:s0:c130,c256,c512,c768 tcontext=u:object_r:property_socket:s0 tclass=sock_file permissive=0 app=swiftstartechnology.co.myapplication
W/o.myapplicatio: JNI critical lock held for 22.800ms on Thread[16,tid=7009,Runnable,Thread*=0xd3be6000,peer=0x12f022e8,"Measurement Worker"]
V/FA: onActivityCreated
W/o.myapplicatio: JNI critical lock held for 19.007ms on Thread[1,tid=6953,Runnable,Thread*=0xea537800,peer=0x72d4f1f0,"main"]
W/o.myapplicatio: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed)
W/o.myapplicatio: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed)
W/o.myapplicatio: Verification of java.lang.Object com.google.firebase.database.collection.ArraySortedMap.getPredecessorKey(java.lang.Object) took 198.119ms
W/DynamiteModule: Local module descriptor class for providerinstaller not found.
I/DynamiteModule: Considering local module providerinstaller:0 and remote module providerinstaller:0
W/ProviderInstaller: Failed to load providerinstaller module: No acceptable module found. Local version is 0 and remote version is 0.
D/ApplicationLoaders: Returning zygote-cached class loader: /system/framework/android.hidl.base-V1.0-java.jar
    Returning zygote-cached class loader: /system/framework/android.hidl.manager-V1.0-java.jar
D/ApplicationLoaders: Returning zygote-cached class loader: /system/framework/android.hidl.base-V1.0-java.jar
I/o.myapplicatio: The ClassLoaderContext is a special shared library.
I/chatty: uid=10130(swiftstartechnology.co.myapplication) AsyncTask #1 identical 1 line
I/o.myapplicatio: The ClassLoaderContext is a special shared library.
I/o.myapplicatio: The ClassLoaderContext is a special shared library.
I/o.myapplicatio: Waiting for a blocking GC ClassLinker
W/o.myapplicatio: Accessing hidden method Lsun/misc/Unsafe;->getLong(Ljava/lang/Object;J)J (greylist,core-platform-api, linking, allowed)
W/o.myapplicatio: Accessing hidden method Lsun/misc/Unsafe;->arrayBaseOffset(Ljava/lang/Class;)I (greylist,core-platform-api, linking, allowed)
    Accessing hidden method Lsun/misc/Unsafe;->copyMemory(JJJ)V (greylist, linking, allowed)
    Accessing hidden method Lsun/misc/Unsafe;->objectFieldOffset(Ljava/lang/reflect/Field;)J (greylist,core-platform-api, linking, allowed)
W/o.myapplicatio: Accessing hidden method Lsun/misc/Unsafe;->getByte(J)B (greylist,core-platform-api, linking, allowed)
    Accessing hidden method Lsun/misc/Unsafe;->getByte(Ljava/lang/Object;J)B (greylist,core-platform-api, linking, allowed)
W/o.myapplicatio: Accessing hidden method Lsun/misc/Unsafe;->getLong(J)J (greylist,core-platform-api, linking, allowed)
W/o.myapplicatio: Accessing hidden method Lsun/misc/Unsafe;->putByte(JB)V (greylist,core-platform-api, linking, allowed)
    Accessing hidden method Lsun/misc/Unsafe;->putByte(Ljava/lang/Object;JB)V (greylist,core-platform-api, linking, allowed)
W/o.myapplicatio: Accessing hidden method Lsun/misc/Unsafe;->getLong(Ljava/lang/Object;J)J (greylist,core-platform-api, reflection, allowed)
W/o.myapplicatio: Accessing hidden method Lsun/misc/Unsafe;->getLong(Ljava/lang/Object;J)J (greylist,core-platform-api, reflection, allowed)
    Accessing hidden field Ljava/nio/Buffer;->address:J (greylist, reflection, allowed)
W/o.myapplicatio: Verification of long com.google.android.gms.internal.measurement.zzji.zzak() took 349.930ms
I/o.myapplicatio: WaitForGcToComplete blocked ClassLinker on ClassLinker for 209.257ms
W/o.myapplicatio: Suspending all threads took: 13.153ms
I/o.myapplicatio: Waiting for a blocking GC ClassLinker
W/o.myapplicatio: Verification of boolean com.google.android.gms.internal.measurement.zzku.zza() took 355.009ms
I/o.myapplicatio: Waiting for a blocking GC ProfileSaver
I/o.myapplicatio: WaitForGcToComplete blocked ClassLinker on HeapTrim for 583.254ms
I/o.myapplicatio: WaitForGcToComplete blocked ProfileSaver on ClassLinker for 198.166ms
W/o.myapplicatio: Accessing hidden field Ldalvik/system/BaseDexClassLoader;->pathList:Ldalvik/system/DexPathList; (greylist, reflection, allowed)
W/o.myapplicatio: Accessing hidden field Ldalvik/system/DexPathList;->nativeLibraryDirectories:Ljava/util/List; (greylist, reflection, allowed)
    Accessing hidden field Ldalvik/system/DexPathList;->systemNativeLibraryDirectories:Ljava/util/List; (greylist, reflection, allowed)
    Accessing hidden field Ldalvik/system/DexPathList;->nativeLibraryPathElements:[Ldalvik/system/DexPathList$NativeLibraryElement; (greylist, reflection, allowed)
W/o.myapplicatio: Accessing hidden method Ldalvik/system/DexPathList;->makePathElements(Ljava/util/List;)[Ldalvik/system/DexPathList$NativeLibraryElement; (greylist, reflection, allowed)
V/NativeCrypto: Registering com/google/android/gms/org/conscrypt/NativeCrypto's 284 native methods...
W/o.myapplicatio: Accessing hidden method Ljava/security/spec/ECParameterSpec;->getCurveName()Ljava/lang/String; (greylist, reflection, allowed)
W/o.myapplicatio: Verification of void com.google.android.gms.internal.measurement.zzlf.<init>() took 176.786ms
D/NetworkSecurityConfig: No Network Security Config specified, using platform default
W/o.myapplicatio: Long monitor contention with owner Measurement Worker (7009) at java.lang.String com.google.android.gms.internal.measurement.zzji.zzd()(com.google.android.gms:play-services-measurement-impl@@17.2.0:3) waiters=0 in java.lang.Object com.google.android.gms.measurement.internal.zzem.zza(java.lang.Object) for 1.318s
I/ProviderInstaller: Installed default security provider GmsCore_OpenSSL
W/o.myapplicatio: Verification of int io.grpc.okhttp.OkHttpChannelBuilder.getDefaultPort() took 107.595ms
I/Choreographer: Skipped 160 frames!  The application may be doing too much work on its main thread.
W/o.myapplicatio: Verification of io.grpc.okhttp.OkHttpChannelBuilder io.grpc.okhttp.OkHttpChannelBuilder.keepAliveTime(long, java.util.concurrent.TimeUnit) took 101.259ms
W/o.myapplicatio: Verification of java.util.List com.google.android.gms.measurement.internal.zzep.zza(int) took 435.406ms
W/o.myapplicatio: Verification of io.grpc.okhttp.OkHttpChannelBuilder io.grpc.okhttp.OkHttpChannelBuilder.negotiationType(io.grpc.okhttp.NegotiationType) took 500.589ms
W/o.myapplicatio: Verification of io.grpc.Status$Code io.grpc.internal.GrpcUtil.httpStatusToGrpcCode(int) took 320.140ms
W/o.myapplicatio: Verification of boolean com.google.android.gms.measurement.internal.zzik.zzai() took 535.111ms
W/o.myapplicatio: Verification of boolean com.google.common.base.Splitter.access$300(com.google.common.base.Splitter) took 337.455ms
D/: HostConnection::get() New Host Connection established 0xd3b8eb40, tid 7010
D/: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_YUV420_888_to_NV21 ANDROID_EMU_YUV_Cache GL_OES_EGL_image_external_essl3 GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_gles_max_version_3_0 
W/o.myapplicatio: Verification of void com.google.android.gms.measurement.internal.zzik.zzal() took 251.289ms
D/eglCodecCommon: setVertexArrayObject: set vao to 0 (0) 0 0
D/EGL_emulation: eglCreateContext: 0xea57f8e0: maj 3 min 0 rcv 3
D/EGL_emulation: eglMakeCurrent: 0xea57f8e0: ver 3 0 (tinfo 0xdf28a440)
W/Gralloc3: mapper 3.x is not supported
D/: createUnique: call
D/: HostConnection::get() New Host Connection established 0xd3b903a0, tid 7010
D/: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_YUV420_888_to_NV21 ANDROID_EMU_YUV_Cache GL_OES_EGL_image_external_essl3 GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_gles_max_version_3_0 
D/eglCodecCommon: allocate: Ask for block of size 0x1000
    allocate: ioctl allocate returned offset 0x3ff1e0000 size 0x2000
W/o.myapplicatio: Verification of void com.google.android.gms.measurement.internal.zzjv.zzb() took 194.624ms
D/EGL_emulation: eglMakeCurrent: 0xea57f8e0: ver 3 0 (tinfo 0xdf28a440)
D/eglCodecCommon: setVertexArrayObject: set vao to 0 (0) 1 0
W/o.myapplicatio: Verification of void com.google.android.gms.measurement.internal.zzjc.onServiceConnected(android.content.ComponentName, android.os.IBinder) took 163.351ms
I/o.myapplicatio: Background young concurrent copying GC freed 8140(493KB) AllocSpace objects, 0(0B) LOS objects, 13% free, 2422KB/2793KB, paused 374.787ms total 2.351s
V/FA: Collection enabled
V/FA: App package, google app id: swiftstartechnology.co.myapplication, 1:51294462735:android:a6f65d170b19201821947a
I/FA: App measurement is starting up, version: 18202
    To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
I/FA: To enable faster debug mode event logging run:
      adb shell setprop debug.firebase.analytics.app swiftstartechnology.co.myapplication
D/FA: Debug-level message logging enabled
I/OpenGLRenderer: Davey! duration=6557ms; Flags=1, IntendedVsync=1141638312900, Vsync=1144304979460, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=1144319481200, AnimationStart=1144319666800, PerformTraversalsStart=1144321228600, DrawStart=1145997500100, SyncQueued=1146132897500, SyncStart=1146142956100, IssueDrawCommandsStart=1146143823000, SwapBuffers=1147827638000, FrameCompleted=1148205756100, DequeueBufferDuration=170000, QueueBufferDuration=2071000, 
W/o.myapplicatio: Verification of void androidx.appcompat.widget.LinearLayoutCompat.forceUniformWidth(int, int) took 128.277ms
I/o.myapplicatio: Background concurrent copying GC freed 2881(238KB) AllocSpace objects, 0(0B) LOS objects, 49% free, 2440KB/4880KB, paused 2.465ms total 932.892ms
W/o.myapplicatio: Verification of io.opencensus.stats.Measure$MeasureLong io.opencensus.stats.Measure$MeasureLong.create(java.lang.String, java.lang.String, java.lang.String) took 239.858ms
W/o.myapplicatio: Verification of void io.grpc.Context$Storage.detach(io.grpc.Context, io.grpc.Context) took 179.086ms
W/o.myapplicatio: JNI critical lock held for 104.996ms on Thread[1,tid=6953,Runnable,Thread*=0xea537800,peer=0x72d4f1f0,"main"]
I/Choreographer: Skipped 289 frames!  The application may be doing too much work on its main thread.
I/OpenGLRenderer: Davey! duration=5294ms; Flags=0, IntendedVsync=1144422475200, Vsync=1149239141674, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=1149249348400, AnimationStart=1149249643400, PerformTraversalsStart=1149465638200, DrawStart=1149474623100, SyncQueued=1149476670800, SyncStart=1149476925500, IssueDrawCommandsStart=1149477859000, SwapBuffers=1149639057700, FrameCompleted=1149716887500, DequeueBufferDuration=138000, QueueBufferDuration=1027000, 
I/Choreographer: Skipped 56 frames!  The application may be doing too much work on its main thread.
W/o.myapplicatio: Verification of java.lang.Object com.google.android.gms.measurement.internal.zzo.createFromParcel(android.os.Parcel) took 292.576ms
I/OpenGLRenderer: Davey! duration=1074ms; Flags=0, IntendedVsync=1149344427750, Vsync=1150277761046, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=1150283529400, AnimationStart=1150283978200, PerformTraversalsStart=1150285002400, DrawStart=1150285966600, SyncQueued=1150286778600, SyncStart=1150288325800, IssueDrawCommandsStart=1150288606100, SwapBuffers=1150319882100, FrameCompleted=1150420590000, DequeueBufferDuration=166000, QueueBufferDuration=613000, 
W/o.myapplicatio: Verification of io.opencensus.common.Scope io.opencensus.trace.SpanBuilder.startScopedSpan() took 160.703ms
W/o.myapplicatio: Verification of void com.google.firebase.firestore.remote.FirestoreChannel$1.onClose(io.grpc.Status, io.grpc.Metadata) took 180.725ms
W/o.myapplicatio: Accessing hidden field Ljava/net/Socket;->impl:Ljava/net/SocketImpl; (greylist, reflection, allowed)
W/o.myapplicatio: Accessing hidden method Ldalvik/system/CloseGuard;->get()Ldalvik/system/CloseGuard; (greylist,core-platform-api, linking, allowed)
W/o.myapplicatio: Accessing hidden method Ldalvik/system/CloseGuard;->open(Ljava/lang/String;)V (greylist,core-platform-api, linking, allowed)
W/o.myapplicatio: Accessing hidden field Ljava/io/FileDescriptor;->descriptor:I (greylist, JNI, allowed)
W/o.myapplicatio: Long monitor contention with owner Measurement Worker (7009) at void java.util.Hashtable$HashtableEntry.<init>(int, java.lang.Object, java.lang.Object, java.util.Hashtable$HashtableEntry)(Hashtable.java:1275) waiters=0 in com.google.firebase.iid.zzay com.google.firebase.iid.zzav.zzb(java.lang.String, java.lang.String, java.lang.String) for 286ms
V/FA: Connecting to remote service
W/o.myapplicatio: Accessing hidden method Ljava/security/spec/ECParameterSpec;->setCurveName(Ljava/lang/String;)V (greylist, reflection, allowed)
W/o.myapplicatio: Accessing hidden method Lsun/security/x509/AlgorithmId;->get(Ljava/lang/String;)Lsun/security/x509/AlgorithmId; (greylist, reflection, allowed)
W/o.myapplicatio: Accessing hidden method Lsun/security/x509/AlgorithmId;->getName()Ljava/lang/String; (greylist,core-platform-api, reflection, allowed)
W/o.myapplicatio: Accessing hidden method Ldalvik/system/BlockGuard;->getThreadPolicy()Ldalvik/system/BlockGuard$Policy; (greylist,core-platform-api, linking, allowed)
W/o.myapplicatio: Accessing hidden method Ldalvik/system/BlockGuard$Policy;->onNetwork()V (greylist, linking, allowed)
V/FA: Connection attempt already in progress
V/FA: Activity resumed, time: 1143917
I/FA: Tag Manager is not found and thus will not be used
D/FA: Logging event (FE): screen_view(_vs), Bundle[{ga_event_origin(_o)=auto, ga_screen_class(_sc)=MainActivity, ga_screen_id(_si)=181627382259492091}]
V/FA: Connection attempt already in progress
V/FA: Connection attempt already in progress
D/FA: Connected to remote service
V/FA: Processing queued up service tasks: 4
W/Firestore: (21.1.1) [OnlineStateTracker]: Could not reach Cloud Firestore backend. Backend didn't respond within 10 seconds

    This typically indicates that your device does not have a healthy Internet connection at the moment. The client will operate in offline mode until it is able to successfully connect to the backend.
W/o.myapplicatio: Accessing hidden method Landroid/graphics/FontFamily;-><init>()V (greylist, reflection, allowed)
W/o.myapplicatio: Accessing hidden method Landroid/graphics/FontFamily;->addFontFromAssetManager(Landroid/content/res/AssetManager;Ljava/lang/String;IZIII[Landroid/graphics/fonts/FontVariationAxis;)Z (greylist, reflection, allowed)
    Accessing hidden method Landroid/graphics/FontFamily;->addFontFromBuffer(Ljava/nio/ByteBuffer;I[Landroid/graphics/fonts/FontVariationAxis;II)Z (greylist, reflection, allowed)
    Accessing hidden method Landroid/graphics/FontFamily;->freeze()Z (greylist, reflection, allowed)
    Accessing hidden method Landroid/graphics/FontFamily;->abortCreation()V (greylist, reflection, allowed)
    Accessing hidden method Landroid/graphics/Typeface;->createFromFamiliesWithDefault([Landroid/graphics/FontFamily;Ljava/lang/String;II)Landroid/graphics/Typeface; (greylist, reflection, allowed)
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
    Process: swiftstartechnology.co.myapplication, PID: 6953
    java.lang.IllegalArgumentException: Cannot format given Object as a Date
        at java.text.DateFormat.format(DateFormat.java:306)
        at java.text.Format.format(Format.java:157)
        at swiftstartechnology.co.myapplication.ThoughtsAdapter$ViewHolder.bindThought(ThoughtsAdapter.kt:42)
        at swiftstartechnology.co.myapplication.ThoughtsAdapter.onBindViewHolder(ThoughtsAdapter.kt:25)
        at swiftstartechnology.co.myapplication.ThoughtsAdapter.onBindViewHolder(ThoughtsAdapter.kt:13)
        at androidx.recyclerview.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:6781)
        at androidx.recyclerview.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:6823)
        at androidx.recyclerview.widget.RecyclerView$Recycler.tryBindViewHolderByDeadline(RecyclerView.java:5752)
        at androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:6019)
        at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5858)
        at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5854)
        at androidx.recyclerview.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2230)
        at androidx.recyclerview.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1557)
        at androidx.recyclerview.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1517)
        at androidx.recyclerview.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:612)
        at androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3924)
        at androidx.recyclerview.widget.RecyclerView.dispatchLayout(RecyclerView.java:3641)
        at androidx.recyclerview.widget.RecyclerView.onLayout(RecyclerView.java:4194)
        at android.view.View.layout(View.java:21927)
        at android.view.ViewGroup.layout(ViewGroup.java:6260)
        at androidx.constraintlayout.widget.ConstraintLayout.onLayout(ConstraintLayout.java:1915)
        at android.view.View.layout(View.java:21927)
        at android.view.ViewGroup.layout(ViewGroup.java:6260)
        at com.google.android.material.appbar.HeaderScrollingViewBehavior.layoutChild(HeaderScrollingViewBehavior.java:142)
        at com.google.android.material.appbar.ViewOffsetBehavior.onLayoutChild(ViewOffsetBehavior.java:41)
        at com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior.onLayoutChild(AppBarLayout.java:1556)
        at androidx.coordinatorlayout.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:888)
        at android.view.View.layout(View.java:21927)
        at android.view.ViewGroup.layout(ViewGroup.java:6260)
        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
        at android.view.View.layout(View.java:21927)
        at android.view.ViewGroup.layout(ViewGroup.java:6260)
        at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1829)
        at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1673)
        at android.widget.LinearLayout.onLayout(LinearLayout.java:1582)
        at android.view.View.layout(View.java:21927)
        at android.view.ViewGroup.layout(ViewGroup.java:6260)
        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
        at android.view.View.layout(View.java:21927)
        at android.view.ViewGroup.layout(ViewGroup.java:6260)
        at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1829)
        at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1673)
        at android.widget.LinearLayout.onLayout(LinearLayout.java:1582)
        at android.view.View.layout(View.java:21927)
        at android.view.ViewGroup.layout(ViewGroup.java:6260)
        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
        at com.android.internal.policy.DecorView.onLayout(DecorView.java:779)
        at android.view.View.layout(View.java:21927)
        at android.view.ViewGroup.layout(ViewGroup.java:6260)
E/AndroidRuntime:     at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:3080)
        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2590)
        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1721)
        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7598)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:966)
        at android.view.Choreographer.doCallbacks(Choreographer.java:790)
        at android.view.Choreographer.doFrame(Choreographer.java:725)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:951)
        at android.os.Handler.handleCallback(Handler.java:883)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7356)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
I/Process: Sending signal. PID: 6953 SIG: 9
Process 6953 terminated.

It seems that I am stuck here would really appreciate some enlightenment

lotor
  • 1,060
  • 7
  • 18
  • I remember solving the exact same problem [here](https://stackoverflow.com/a/57589262/11342519). Seems like there is a bug in a tutorial of some kind. – jsamol Sep 23 '19 at 23:40
  • Thank you for the help that piece of code seems to be working fine now with the edits but the emulator still just displays the 4 toggle buttons and the FAB on the main screen and now I have a crash with the following code: val newThought = Thought( name, timestamp, thoughtText, numberLikes?.toInt(), numberComments?.toInt() ) thoughts.add(newThought) can you please assist I am really at my wits end here. – Swiftstar Technology Sep 24 '19 at 20:30
  • Hello jsamol... there seems to be more bugs I am stuck at this part: val newThought = Thought( name, timestamp, thoughtText, numberLikes?.toInt(), numberComments?.toInt() ) thoughts.add(newThought) The app crashes when I add this part. Do you perhaps know what is going wrong? – Swiftstar Technology Sep 25 '19 at 17:46
  • Can you update your question with an error you are getting on this line? – jsamol Sep 26 '19 at 09:13
  • jsamol I have edited the question thank you. I really appreciate your efforts – Swiftstar Technology Sep 26 '19 at 19:03
  • The error indicates that you try to invoke the `DateFormat.format()` method on an object that isn't a `Date` instance. What does the `Thought` class look like? – jsamol Sep 26 '19 at 20:55
  • data class Thought constructor(val username: String?,val timestamp: Timestamp?, val thoughtText: String?, val numberLikes: Int?, val numberComments: Int?, val documentId: String?) – Swiftstar Technology Sep 27 '19 at 08:54
  • and also have date format as:val dateFormatter = SimpleDateFormat("MMM d, h:mm a", Locale.getDefault ()) val dateString = dateFormatter.format(thought.timestamp) timestamp?.text = dateString – Swiftstar Technology Sep 27 '19 at 08:57
  • hello jsamol...the data class Thought constructor(val username: String?,val timestamp: Timestamp?, val thoughtText: String?, val numberLikes: Int?, val numberComments: Int?, val documentId: String?) – Swiftstar Technology Sep 29 '19 at 10:57

1 Answers1

0

You are getting an error because you are trying to invoke the DateFormat.format() method on an object that is of type Timestamp while the method only takes Date as an argument.

If you are using the Firebase Timestamp class, you can use the Timestamp.toDate() method in order to convert your object to Date:

val dateString = thought.timestamp?.let { dateFormatter.format(it.toDate()) } ?: "" // if `thought.timestamp` is null, `dateString` is an empty string

If you are using Java Timestamp, you can convert it to Date like this:

val date = thought.timestamp?.let { Date(it.time) } // if `thought.timestamp` is null, `date` is also null
val dateString = date?.let { dateFromatter.format(it) } ?: "" // if `date` is null, `dateString` is an empty string
jsamol
  • 3,042
  • 2
  • 16
  • 27
  • soI did that and got this error:java.lang.NullPointerException: Attempt to invoke virtual method 'long java.util.Date.getTime()' on a null object reference and a calendar error so I changed it to val dateString = dateFormatter.format(Date ()) now only the likeimage and current date and time is displaying in the emulator – Swiftstar Technology Sep 30 '19 at 21:54
  • @SwiftstarTechnology You're getting a `NullPointerException` because `thought.timestamp` is apparently `null`. I forgot `timestamp` was nullable, my bad. I've edited my answer and provided examples of dealing with nullable `timestamp` values. You may want to check [what a `NullPointerException` is](https://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) and [how to deal with `null`s safely in Kotlin](https://kotlinlang.org/docs/reference/null-safety.html). – jsamol Oct 01 '19 at 09:54
  • Okay thank you. I have read the articles and I have made the amendments how ever now the Firebase data is not displaying anything in the emulator besides the likes images(which matches the amount of thoughts/post made)...Do you perhaps have a link to the code you used for this project? I just want to compare it to what I have please – Swiftstar Technology Oct 01 '19 at 17:00
  • @SwiftstarTechnology I'm sorry, but I haven't worked on such a project, I'm just trying to help based on the information provided by you (and the author of the other question). If you are facing some other problems with Firebase, you should probably consider posting a new question describing the new issue as this one has become quite broad and a little drifted away from the original subject. – jsamol Oct 01 '19 at 19:54
  • @jsamol...that is true thank you for all your assistance I really appreciate it – Swiftstar Technology Oct 01 '19 at 19:59