I am trying to pass an ArrayList of an objects called Node. The Node object has an attribute called Vertex which is an object of a class Vertex. Both of these classes extend Parcelable. They are both nested classed in class FloorPlan but the code of this class is too long to post. When I run my and the ArrayList has only one object in it then it works fine. However if there is more than one object I get a Run Time Error.
This is my Node.java class
Node.java:
public static class Node implements Parcelable{
Vertex v;
Graph graph;
public Node parent;
public double f;
public double gCost;
public double h;
public Node(Vertex v,Node parent, double f, double gCost){
this.v = v;
this.parent= parent;
this.gCost = gCost;
this.h = h;
this.f= this.gCost + this.h;
}
public List<Vertex> getNeighbours(Vertex v){
return graph.getNeighbors(v);
}
public void setParent(Node n){
this.parent = n;
}
public void updateG (double gCost){
this.gCost = this.gCost + gCost;
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeParcelable(v, flags);
dest.writeParcelable(parent, flags);
dest.writeDouble(f);
dest.writeDouble(gCost);
dest.writeDouble(h);
}
public static final Parcelable.Creator<Node> CREATOR = new Creator<Node>() {
public Node createFromParcel(Parcel source) {
return new Node(source);
}
public Node[] newArray(int size) {
return new Node[size];
}
};
}
This is my Vertex.java class
Vertex.java
public class Vertex implements Parcelable {
/**
* @param args
*/
String vertexName;
int x;
int y;
int z;
//Vertex vert;
public Vertex(String vertName, int x,int y, int z){
vertexName = vertName;
this.x = x;
this.y = y;
this.z = z;
}
public String getVertexNum(){
return vertexName;
}
public int getX(){
return x;
}
public int getY(){
return y;
}
public int getZ(){
return z;
}
public double distanceTo(Vertex other){
return Math.sqrt( Math.pow( x -other.x, 2) + Math.pow( y- other.y,2)+ Math.pow( z- other.z,2) );
}
@Override
public int describeContents() {
// TODO Auto-generated method stub
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(vertexName);
dest.writeInt(x);
dest.writeInt(y);
dest.writeInt(z);
// TODO Auto-generated method stub
}
public Vertex(Parcel in){ // -- Line 1092
this.vertexName = in.readString();
this.x = in.readInt();
this.y =in.readInt();
this.z = in.readInt();
}
public final Parcelable.Creator<Vertex> CREATOR = new Creator<Vertex>() {
public Vertex createFromParcel(Parcel source) {
return new Vertex(source);
}
public Vertex[] newArray(int size) {
return new Vertex[size];
}
};
}
This is how I pass the bundle
Intent menuIntent = new Intent("com.example.helloworld3.FLOORPLANTWO");
Bundle b = new Bundle()
b.putParcelableArrayList("rooms",(ArrayList<? extends Parcelable>) subpathtwo);
menuIntent.putExtras(b);
menuIntent.setClass(FloorPlan.this, FloorPlanTwo.class);
startActivity(menuIntent);
And that's how I receive it:
B
undle b = this.getIntent().getExtras();
subpathtwo= b.getParcelableArrayList("rooms"); // -- FloorPlanTwo line 21
This is what In the LogCat:
04-07 17:14:17.104: D/dalvikvm(795): GC_EXTERNAL_ALLOC freed 67K, 49% free 2754K/5379K, external 1625K/2137K, paused 37ms
04-07 17:14:17.248: D/(795): HostConnection::get() New Host Connection established 0x940a500, tid 795
04-07 17:14:28.244: W/KeyCharacterMap(795): No keyboard for id 0
04-07 17:14:28.244: W/KeyCharacterMap(795): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
04-07 17:14:41.053: D/dalvikvm(795): GC_EXTERNAL_ALLOC freed 108K, 48% free 2882K/5511K, external 2425K/2961K, paused 41ms
04-07 17:14:41.208: I/System.out(795): C201
04-07 17:14:41.208: I/System.out(795): 51
04-07 17:14:41.208: I/System.out(795): 89
04-07 17:14:41.208: I/System.out(795): C2Exit5
04-07 17:14:41.212: I/System.out(795): 42
04-07 17:14:41.212: I/System.out(795): 164
04-07 17:14:41.212: I/System.out(795): C1Exit1
04-07 17:14:41.212: I/System.out(795): 52
04-07 17:14:41.216: I/System.out(795): 174
04-07 17:14:41.216: I/System.out(795): C108
04-07 17:14:41.216: I/System.out(795): 51
04-07 17:14:41.216: I/System.out(795): 89
04-07 17:14:41.372: I/System.out(795): 52.0
04-07 17:14:41.372: I/System.out(795): 174.0
04-07 17:14:41.376: I/System.out(795): 51.0
04-07 17:14:41.376: I/System.out(795): 89.0
04-07 17:15:01.244: D/AndroidRuntime(795): Shutting down VM
04-07 17:15:01.244: W/dalvikvm(795): threadid=1: thread exiting with uncaught exception (group=0xb608f4f0)
04-07 17:15:01.253: E/AndroidRuntime(795): FATAL EXCEPTION: main
04-07 17:15:01.253: E/AndroidRuntime(795): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.helloworld3/com.example.helloworld3.FloorPlanTwo}: java.lang.RuntimeException: Parcel android.os.Parcel@b658b518: Unmarshalling unknown type code 40 at offset 120
04-07 17:15:01.253: E/AndroidRuntime(795): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
04-07 17:15:01.253: E/AndroidRuntime(795): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
04-07 17:15:01.253: E/AndroidRuntime(795): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
04-07 17:15:01.253: E/AndroidRuntime(795): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
04-07 17:15:01.253: E/AndroidRuntime(795): at android.os.Handler.dispatchMessage(Handler.java:99)
04-07 17:15:01.253: E/AndroidRuntime(795): at android.os.Looper.loop(Looper.java:130)
04-07 17:15:01.253: E/AndroidRuntime(795): at android.app.ActivityThread.main(ActivityThread.java:3683)
04-07 17:15:01.253: E/AndroidRuntime(795): at java.lang.reflect.Method.invokeNative(Native Method)
04-07 17:15:01.253: E/AndroidRuntime(795): at java.lang.reflect.Method.invoke(Method.java:507)
04-07 17:15:01.253: E/AndroidRuntime(795): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-07 17:15:01.253: E/AndroidRuntime(795): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-07 17:15:01.253: E/AndroidRuntime(795): at dalvik.system.NativeStart.main(Native Method)
04-07 17:15:01.253: E/AndroidRuntime(795): Caused by: java.lang.RuntimeException: Parcel android.os.Parcel@b658b518: Unmarshalling unknown type code 40 at offset 120
04-07 17:15:01.253: E/AndroidRuntime(795): at android.os.Parcel.readValue(Parcel.java:1913)
04-07 17:15:01.253: E/AndroidRuntime(795): at android.os.Parcel.readListInternal(Parcel.java:2092)
04-07 17:15:01.253: E/AndroidRuntime(795): at android.os.Parcel.readArrayList(Parcel.java:1536)
04-07 17:15:01.253: E/AndroidRuntime(795): at android.os.Parcel.readValue(Parcel.java:1867)
04-07 17:15:01.253: E/AndroidRuntime(795): at android.os.Parcel.readMapInternal(Parcel.java:2083)
04-07 17:15:01.253: E/AndroidRuntime(795): at android.os.Bundle.unparcel(Bundle.java:208)
04-07 17:15:01.253: E/AndroidRuntime(795): at android.os.Bundle.getParcelable(Bundle.java:1100)
04-07 17:15:01.253: E/AndroidRuntime(795): at com.example.helloworld3.FloorPlanTwo.onCreate(FloorPlanTwo.java:21)
04-07 17:15:01.253: E/AndroidRuntime(795): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-07 17:15:01.253: E/AndroidRuntime(795): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
04-07 17:15:01.253: E/AndroidRuntime(795): ... 11 more
Thank you for all your help!
0 comments:
Post a Comment