最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

android - Class not found when unmarshalling: com.google.firebase.Timestamp, - Stack Overflow

matteradmin15PV0评论

I am trying to send a timestamp to another activity using intent.putExtra("timeStamp", timeStamp) however on some versions of android (it seems to be older versions in general) I get the following error:

Class not found when unmarshalling: com.google.firebase.Timestamp
java.lang.ClassNotFoundException: com.google.firebase.Timestamp
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:454)
at android.os.Parcel.readParcelableCreator(Parcel.java:3338)
at android.os.Parcel.readParcelable(Parcel.java:3272)
at android.os.Parcel.readValue(Parcel.java:3174)
at android.os.Parcel.readArrayMapInternal(Parcel.java:3567)
at android.os.BaseBundle.initializeFromParcelLocked(BaseBundle.java:292)
at android.os.BaseBundle.unparcel(BaseBundle.java:236)
at android.os.BaseBundle.getString(BaseBundle.java:1196)
at m.sm.a(:com.google.android.gms.dynamite_measurementdynamite@[email protected] (150400-0):42)
at com.google.android.gms.measurement.internal.AppMeasurementDynamiteService.onActivityCreatedByScionActivityInfo(:com.google.android.gms.dynamite_measurementdynamite@[email protected] (150400-0):23)
at m.io.v(:com.google.android.gms.dynamite_measurementdynamite@[email protected] (150400-0):33)
at m.bx.onTransact(:com.google.android.gms.dynamite_measurementdynamite@[email protected] (150400-0):21)
at android.os.Binder.transact(Binder.java:1052)
at com.google.android.gms.internal.measurement.zzbu.zzb(com.google.android.gms:play-services-measurement-base@@22.2.0:21)
at com.google.android.gms.internal.measurement.zzdn.onActivityCreatedByScionActivityInfo(com.google.android.gms:play-services-measurement-base@@22.2.0:123)
at com.google.android.gms.internal.measurement.zzfq.zza(com.google.android.gms:play-services-measurement-sdk-api@@22.2.0:11)
at com.google.android.gms.internal.measurement.zzed$zzb.run(com.google.android.gms:play-services-measurement-sdk-api@@22.2.0:12)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:923)
Caused by: java.lang.ClassNotFoundException: com.google.firebase.Timestamp
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:1358)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:1418)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at java.lang.Class.classForName(Native Method) 
at java.lang.Class.forName(Class.java:454) 
at android.os.Parcel.readParcelableCreator(Parcel.java:3338)                                                                                                        at android.os.Parcel.readParcelable(Parcel.java:3272) 
at android.os.Parcel.readValue(Parcel.java:3174) 
at android.os.Parcel.readArrayMapInternal(Parcel.java:3567) 
at android.os.BaseBundle.initializeFromParcelLocked(BaseBundle.java:292) 
at android.os.BaseBundle.unparcel(BaseBundle.java:236) 
at android.os.BaseBundle.getString(BaseBundle.java:1196) 
at m.sm.a(:com.google.android.gms.dynamite_measurementdynamite@[email protected] (150400-0):42) 
at com.google.android.gms.measurement.internal.AppMeasurementDynamiteService.onActivityCreatedByScionActivityInfo(:com.google.android.gms.dynamite_measurementdynamite@[email protected] (150400-0):23) 
at m.io.v(:com.google.android.gms.dynamite_measurementdynamite@[email protected] (150400-0):33) 
at m.bx.onTransact(:com.google.android.gms.dynamite_measurementdynamite@[email protected] (150400-0):21) 
at android.os.Binder.transact(Binder.java:1052) 
at com.google.android.gms.internal.measurement.zzbu.zzb(com.google.android.gms:play-services-measurement-base@@22.2.0:21) 
at com.google.android.gms.internal.measurement.zzdn.onActivityCreatedByScionActivityInfo(com.google.android.gms:play-services-measurement-base@@22.2.0:123) 
at com.google.android.gms.internal.measurement.zzfq.zza(com.google.android.gms:play-services-measurement-sdk-api@@22.2.0:11) 
at com.google.android.gms.internal.measurement.zzed$zzb.run(com.google.android.gms:play-services-measurement-sdk-api@@22.2.0:12) 
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 
at java.lang.Thread.run(Thread.java:923) 
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available

I tried to use a couple of different things to see if they might work, but none of them worked and some of them even made this error happen in all versions or made the code that used the Timestamp completely stop working all together. Here are some of the things I have tried so far:

Attempt 1:

activity 1: intent.putExtra("timeStamp", timeStamp)

activity 2:

val timeStamp = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
                intent.getParcelableExtra("timeStamp", Timestamp::class.java)
            } else {
                intent.getParcelableExtra<Timestamp>("timeStamp")
            }

Attempt 2:

activity 1: intent.putExtra("timeStamp", timeStamp)

activity 2:

intent.setExtrasClassLoader(Timestamp::class.java.classLoader)
val timeStamp = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
                intent.getParcelableExtra("timeStamp", Timestamp::class.java)
            } else {
                intent.getParcelableExtra<Timestamp>("timeStamp")
            }

Attempt 3:

activity 1:

intent.setExtrasClassLoader(Timestamp::class.java.classLoader)
intent.putExtra("timeStamp", timeStamp)

activity 2:

val timeStamp = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
                intent.getParcelableExtra("timeStamp", Timestamp::class.java)
            } else {
                intent.getParcelableExtra<Timestamp>("timeStamp")
            }

Attempt 4 (since Timestamps weren't working I tried Longs and converting them back):

activity 1: intent.putExtra("timeStampLong", claim.sentTime.seconds)

activity 2:

val timeStampLong = intent.getLongExtra("timeStampLong", -1L)
val timeStamp = Timestamp(Date(timeStampLong))

While attempt 4 did seem to work initially the Timestamp seems to convert it incorrectly (I have used a similar conversion somewhere else in my code and it works fine) as when I then try to use the timestamp it doesn't do anything

I am trying to send a timestamp to another activity using intent.putExtra("timeStamp", timeStamp) however on some versions of android (it seems to be older versions in general) I get the following error:

Class not found when unmarshalling: com.google.firebase.Timestamp
java.lang.ClassNotFoundException: com.google.firebase.Timestamp
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:454)
at android.os.Parcel.readParcelableCreator(Parcel.java:3338)
at android.os.Parcel.readParcelable(Parcel.java:3272)
at android.os.Parcel.readValue(Parcel.java:3174)
at android.os.Parcel.readArrayMapInternal(Parcel.java:3567)
at android.os.BaseBundle.initializeFromParcelLocked(BaseBundle.java:292)
at android.os.BaseBundle.unparcel(BaseBundle.java:236)
at android.os.BaseBundle.getString(BaseBundle.java:1196)
at m.sm.a(:com.google.android.gms.dynamite_measurementdynamite@[email protected] (150400-0):42)
at com.google.android.gms.measurement.internal.AppMeasurementDynamiteService.onActivityCreatedByScionActivityInfo(:com.google.android.gms.dynamite_measurementdynamite@[email protected] (150400-0):23)
at m.io.v(:com.google.android.gms.dynamite_measurementdynamite@[email protected] (150400-0):33)
at m.bx.onTransact(:com.google.android.gms.dynamite_measurementdynamite@[email protected] (150400-0):21)
at android.os.Binder.transact(Binder.java:1052)
at com.google.android.gms.internal.measurement.zzbu.zzb(com.google.android.gms:play-services-measurement-base@@22.2.0:21)
at com.google.android.gms.internal.measurement.zzdn.onActivityCreatedByScionActivityInfo(com.google.android.gms:play-services-measurement-base@@22.2.0:123)
at com.google.android.gms.internal.measurement.zzfq.zza(com.google.android.gms:play-services-measurement-sdk-api@@22.2.0:11)
at com.google.android.gms.internal.measurement.zzed$zzb.run(com.google.android.gms:play-services-measurement-sdk-api@@22.2.0:12)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:923)
Caused by: java.lang.ClassNotFoundException: com.google.firebase.Timestamp
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:1358)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:1418)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at java.lang.Class.classForName(Native Method) 
at java.lang.Class.forName(Class.java:454) 
at android.os.Parcel.readParcelableCreator(Parcel.java:3338)                                                                                                        at android.os.Parcel.readParcelable(Parcel.java:3272) 
at android.os.Parcel.readValue(Parcel.java:3174) 
at android.os.Parcel.readArrayMapInternal(Parcel.java:3567) 
at android.os.BaseBundle.initializeFromParcelLocked(BaseBundle.java:292) 
at android.os.BaseBundle.unparcel(BaseBundle.java:236) 
at android.os.BaseBundle.getString(BaseBundle.java:1196) 
at m.sm.a(:com.google.android.gms.dynamite_measurementdynamite@[email protected] (150400-0):42) 
at com.google.android.gms.measurement.internal.AppMeasurementDynamiteService.onActivityCreatedByScionActivityInfo(:com.google.android.gms.dynamite_measurementdynamite@[email protected] (150400-0):23) 
at m.io.v(:com.google.android.gms.dynamite_measurementdynamite@[email protected] (150400-0):33) 
at m.bx.onTransact(:com.google.android.gms.dynamite_measurementdynamite@[email protected] (150400-0):21) 
at android.os.Binder.transact(Binder.java:1052) 
at com.google.android.gms.internal.measurement.zzbu.zzb(com.google.android.gms:play-services-measurement-base@@22.2.0:21) 
at com.google.android.gms.internal.measurement.zzdn.onActivityCreatedByScionActivityInfo(com.google.android.gms:play-services-measurement-base@@22.2.0:123) 
at com.google.android.gms.internal.measurement.zzfq.zza(com.google.android.gms:play-services-measurement-sdk-api@@22.2.0:11) 
at com.google.android.gms.internal.measurement.zzed$zzb.run(com.google.android.gms:play-services-measurement-sdk-api@@22.2.0:12) 
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 
at java.lang.Thread.run(Thread.java:923) 
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available

I tried to use a couple of different things to see if they might work, but none of them worked and some of them even made this error happen in all versions or made the code that used the Timestamp completely stop working all together. Here are some of the things I have tried so far:

Attempt 1:

activity 1: intent.putExtra("timeStamp", timeStamp)

activity 2:

val timeStamp = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
                intent.getParcelableExtra("timeStamp", Timestamp::class.java)
            } else {
                intent.getParcelableExtra<Timestamp>("timeStamp")
            }

Attempt 2:

activity 1: intent.putExtra("timeStamp", timeStamp)

activity 2:

intent.setExtrasClassLoader(Timestamp::class.java.classLoader)
val timeStamp = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
                intent.getParcelableExtra("timeStamp", Timestamp::class.java)
            } else {
                intent.getParcelableExtra<Timestamp>("timeStamp")
            }

Attempt 3:

activity 1:

intent.setExtrasClassLoader(Timestamp::class.java.classLoader)
intent.putExtra("timeStamp", timeStamp)

activity 2:

val timeStamp = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
                intent.getParcelableExtra("timeStamp", Timestamp::class.java)
            } else {
                intent.getParcelableExtra<Timestamp>("timeStamp")
            }

Attempt 4 (since Timestamps weren't working I tried Longs and converting them back):

activity 1: intent.putExtra("timeStampLong", claim.sentTime.seconds)

activity 2:

val timeStampLong = intent.getLongExtra("timeStampLong", -1L)
val timeStamp = Timestamp(Date(timeStampLong))

While attempt 4 did seem to work initially the Timestamp seems to convert it incorrectly (I have used a similar conversion somewhere else in my code and it works fine) as when I then try to use the timestamp it doesn't do anything

Share Improve this question asked Feb 17 at 19:03 Para1lifePara1life 271 silver badge7 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

Attempt 4 should work, since it's just managing java native longs, but you just didn't do it correctly.

Firstly, Timestamp has two numbers in it, not one. If you want the same Timestamp object after deserialization, you will need to

  1. Serialize both the seconds and nanoseconds values into the Bundle
  2. Deserialize both numbers on the other side out of the Bundle
  3. Pass both numbers to the Timestamp constructor that takes both values. Using a java Date object will not work the way you're using it (the Date constructor using a single long value takes a value in milliseconds, not seconds), and so will lose the original nanoseconds precision.
val seconds = intent.getLongExtra("timeStampSeconds", -1L)
val nanoseconds = intent.getLongExtra("timeStampNanoseconds", -1L)
val t = Timestamp(seconds, nanoseconds)

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far