Reputation: 40454
I have an Object variable that contains a String[] array, and I am trying to do the following
String[] arr = ((String[])packet.getObject());
I however recieve the dreaded ClassCastException. What information do you guys need? My packet class looks as the following:
public class Packet implements Serializable {
private static final long serialVersionUID = 1L;
private int type;
private Object object;
public Packet(int type, Object object) {
this.type = type;
this.object = object;
}
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
public Object getObject() {
return object;
}
public void setObject(Object object) {
this.object = object;
}
}
Any ideas? I'm trying to convert the Object into a String[].
Upvotes: 0
Views: 100
Reputation: 691715
If you get a ClassCastException, it means that the packet does NOT hold a String[]
.
Execute the following code to see what it actually holds, then debug to see why and where the object is stored in the packet:
System.out.println(packet.getObject());
System.out.println(packet.getObject().getClass());
A debugger would give you this information without needing to modify the code.
Upvotes: 3