我通过 Intent 将对象通道从一个活动传递到另一个活动。我使用 Parceler。应用程序崩溃说它找不到虚拟方法getLatitude()
。
我收到了这个错误:
--------- beginning of crash
06-30 16:28:48.501 E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.app.debug, PID: 22168
java.lang.NoSuchMethodError: No virtual method getLatitude()D in class Lim/grouvi/app/entity/LocationDetails; or its super classes (declaration of 'im.grouvi.app.entity.LocationDetails' appears in /data/app/com.example.app.debug-1/split_lib_slice_6_apk.apk)
at im.grouvi.app.entity.LocationDetails$$Parcelable.write(LocationDetails$$Parcelable.java:40)
at im.grouvi.app.entity.Channel$$Parcelable.write(Channel$$Parcelable.java:56)
at im.grouvi.app.entity.Membership$$Parcelable.write(Membership$$Parcelable.java:51)
at im.grouvi.app.entity.Membership$$Parcelable.writeToParcel(Membership$$Parcelable.java:30)
at android.os.Parcel.writeParcelable(Parcel.java:1496)
at android.os.Parcel.writeValue(Parcel.java:1402)
我的 LocationDetails 类:
import org.parceler.Parcel
import java.util.*
@Parcel(Parcel.Serialization.BEAN)
class LocationDetails {
var name: String? = null
@JsonProperty("country_code")
var countryCode: String? = null
var latitude: Double? = null
var longitude: Double? = null
@JsonIgnore
fun dataIsConsistent(): Boolean {
return !TextUtils.isEmpty(name) && (longitude != 0.0) and (latitude != 0.0)
}
val mappedLocation: Map<String, Any>
get() {
val params = HashMap<String, Any>()
name?.let { params.put("name", it) }
countryCode?.let { params.put("country_code", it) }
latitude?.let { params.put("latitude", it) }
longitude?.let { params.put("longitude", it) }
return params
}
}
具有 LocationDetails 的父类 Channel
import org.parceler.Parcel
import org.parceler.Transient
import java.util.*
@JsonIgnoreProperties(ignoreUnknown = true)
@Parcel(Parcel.Serialization.BEAN)
open class Channel : Model {
...
var location: LocationDetails? = null
...
}
另一位家长会员:
@JsonIgnoreProperties(ignoreUnknown = true)
@org.parceler.Parcel(org.parceler.Parcel.Serialization.BEAN)
class Membership : Model, Comparable<Membership> {
...
var channel: Channel? = null
...
}