admin 管理员组文章数量: 1086019
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 badges1 Answer
Reset to default 1Attempt 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
- Serialize both the seconds and nanoseconds values into the Bundle
- Deserialize both numbers on the other side out of the Bundle
- 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)
本文标签: androidClass not found when unmarshalling comgooglefirebaseTimestamp Stack Overflow
版权声明:本文标题:android - Class not found when unmarshalling: com.google.firebase.Timestamp, - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1740132393a2139648.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论