我想将类 Object 发送到另一个包含 Latlng 的活动。但它给出了例外。下面是我的课程,它有 latlng 字段。
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.Keep;
import com.google.android.gms.maps.model.LatLng;
import java.io.Serializable;
public class Institute implements Serializable,Parcelable {
private String instituteName;
private LatLng latLng;
protected Institute(Parcel in) {
instituteName = in.readString();
latLng = in.readParcelable(LatLng.class.getClassLoader());
}
public static final Creator<Institute> CREATOR = new Creator<Institute>() {
@Override
public Institute createFromParcel(Parcel in) {
return new Institute(in);
}
@Override
public Institute[] newArray(int size) {
return new Institute[size];
}
};
@Override
public void writeToParcel(Parcel parcel, int i) {
parcel.writeString(instituteName);
parcel.writeParcelable(latLng,PARCELABLE_WRITE_RETURN_VALUE);
}
public String getInstituteName() {
return instituteName;
}
public void setInstituteName(String instituteName) {
this.instituteName = instituteName;
}
public void setLatLng(LatLng latLng) {
this.latLng = latLng;
}
public LatLng getLatLng() {
return latLng;
}
}
它给了我以下例外
FATAL EXCEPTION: main
Process: in.thoughtsmith.jink, PID: 24906
java.lang.RuntimeException: Unable to start activity ComponentInfo{in.thoughtsmith.jink/in.thoughtsmith.jink.InstituteDetails}: android.os.BadParcelableException: ClassNotFoundException when unmarshalling: Seed0004
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.access$900(ActivityThread.java:150)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: android.os.BadParcelableException: ClassNotFoundException when unmarshalling: Seed0004
at android.os.Parcel.readParcelableCreator(Parcel.java:2432)
at android.os.Parcel.readParcelable(Parcel.java:2358)
at in.thoughtsmith.jink.Institute.<init>(Institute.java:45)
at in.thoughtsmith.jink.Institute$1.createFromParcel(Institute.java:55)
at in.thoughtsmith.jink.Institute$1.createFromParcel(Institute.java:52)
at android.os.Parcel.readParcelable(Parcel.java:2367)
at android.os.Parcel.readValue(Parcel.java:2264)
at android.os.Parcel.readArrayMapInternal(Parcel.java:2614)
at android.os.BaseBundle.unparcel(BaseBundle.java:221)
at android.os.Bundle.getParcelable(Bundle.java:786)
at in.thoughtsmith.jink.InstituteDetails.onCreate(InstituteDetails.kt:34)
at android.app.Activity.performCreate(Activity.java:6285)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.access$900(ActivityThread.java:150)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
请帮助我如何将包含 latlng 的课程发送到另一个活动。也请让我知道有没有更好的方法来实现同样的目标