无法将LatLng对象从片段传递到活动

时间:2017-10-07 05:07:19

标签: android android-fragments geolocation android-fragmentactivity

我正在尝试将Location对象传递给片段中的另一个活动,但我收到了这些错误。

FATAL EXCEPTION: main
                                                                Process: com.shaby.lifeline, PID: 24143
                                                                java.lang.RuntimeException: Parcelable encountered IOException writing serializable object (name = com.shaby.lifeline.pojo.SearchListProvider)
                                                                    at android.os.Parcel.writeSerializable(Parcel.java:1388)
                                                                    at android.os.Parcel.writeValue(Parcel.java:1335)
                                                                    at android.os.Parcel.writeArrayMapInternal(Parcel.java:638)
                                                                    at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1313)
                                                                    at android.os.Bundle.writeToParcel(Bundle.java:1096)
                                                                    at android.os.Parcel.writeBundle(Parcel.java:663)
                                                                    at android.support.v4.app.FragmentState.writeToParcel(Fragment.java:148)
                                                                    at android.os.Parcel.writeTypedArray(Parcel.java:1191)
                                                                    at android.support.v4.app.FragmentManagerState.writeToParcel(FragmentManager.java:564)
                                                                    at android.os.Parcel.writeParcelable(Parcel.java:1357)
                                                                    at android.os.Parcel.writeValue(Parcel.java:1262)
                                                                    at android.os.Parcel.writeArrayMapInternal(Parcel.java:638)
                                                                    at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1313)
                                                                    at android.os.Bundle.writeToParcel(Bundle.java:1096)
                                                                    at android.os.Parcel.writeBundle(Parcel.java:663)
                                                                    at android.app.ActivityManagerProxy.activityStopped(ActivityManagerNative.java:2969)
                                                                    at android.app.ActivityThread$StopInfo.run(ActivityThread.java:3450)
                                                                    at android.os.Handler.handleCallback(Handler.java:810)
                                                                    at android.os.Handler.dispatchMessage(Handler.java:99)
                                                                    at android.os.Looper.loop(Looper.java:189)
                                                                    at android.app.ActivityThread.main(ActivityThread.java:5529)
                                                                    at java.lang.reflect.Method.invoke(Native Method)
                                                                    at java.lang.reflect.Method.invoke(Method.java:372)
                                                                    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:950)
                                                                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:745)
                                                                 Caused by: java.io.NotSerializableException: com.google.android.gms.maps.model.LatLng
                                                                    at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1344)
                                                                    at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1651)
                                                                    at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1497)
                                                                    at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1461)
                                                                    at java.io.ObjectOutputStream.writeFieldValues(ObjectOutputStream.java:959)
                                                                    at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:360)
                                                                    at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1054)
                                                                    at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1384)
                                                                    at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1651)
                                                                    at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1497)
                                                                    at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1461)
                                                                    at android.os.Parcel.writeSerializable(Parcel.java:1383)
                                                                    at android.os.Parcel.writeValue(Parcel.java:1335) 
                                                                    at android.os.Parcel.writeArrayMapInternal(Parcel.java:638) 
                                                                    at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1313) 
                                                                    at android.os.Bundle.writeToParcel(Bundle.java:1096) 
                                                                    at android.os.Parcel.writeBundle(Parcel.java:663) 
                                                                    at android.support.v4.app.FragmentState.writeToParcel(Fragment.java:148) 
                                                                    at android.os.Parcel.writeTypedArray(Parcel.java:1191) 
                                                                    at android.support.v4.app.FragmentManagerState.writeToParcel(FragmentManager.java:564) 
                                                                    at android.os.Parcel.writeParcelable(Parcel.java:1357) 
                                                                    at android.os.Parcel.writeValue(Parcel.java:1262) 
                                                                    at android.os.Parcel.writeArrayMapInternal(Parcel.java:638) 
                                                                    at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1313) 
                                                                    at android.os.Bundle.writeToParcel(Bundle.java:1096) 
                                                                    at android.os.Parcel.writeBundle(Parcel.java:663) 
                                                                    at android.app.ActivityManagerProxy.activityStopped(ActivityManagerNative.java:2969) 
                                                                    at android.app.ActivityThread$StopInfo.run(ActivityThread.java:3450) 
                                                                    at android.os.Handler.handleCallback(Handler.java:810) 
                                                                    at android.os.Handler.dispatchMessage(Handler.java:99) 
                                                                    at android.os.Looper.loop(Looper.java:189) 
                                                                    at android.app.ActivityThread.main(ActivityThread.java:5529) 
                                                                    at java.lang.reflect.Method.invoke(Native Method) 
                                                                    at java.lang.reflect.Method.invoke(Method.java:372) 
                                                                    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:950) 
                                                                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:745) 

我尝试以parceable对象的形式传递它作为一个包但仍然是同样的错误。我尝试过改变活动然后就没事了。

当我将地点作为地块传递时,这是代码。

Intent intent= new Intent(getActivity(), ConfirmBookingActivity.class);
                Bundle b= new Bundle();
                b.putParcelable("source_marker", sourceMarker.getPosition());
                b.putParcelable("destination_marker", destinationMarker.getPosition());
                intent.putExtras(b);
                startActivity(intent);

此外,当我尝试将位置作为字符串传递时,同样的异常仍然存在,我不知道为什么?

0 个答案:

没有答案