ClassCastException in Connector.java code
Hi All,
I understand what ClassCastException is. This is the code from one of the CLDC API's provided (Connector.java) which causes the exception :-
public static DataInputStream openDataInputStream(String name)
throws IOException {
InputConnection con =
(InputConnection)Connector.open(name, Connector.READ);
try {
return con.openDataInputStream();
} finally {
con.close();
}
}
Connector.open() is supposed to return a new Connection object. I am trying to cast it to Inputconnection which is a subinterface of Connection. With this error I am unable to create any network connection. The name string I am providing is "datagram://1.9.67.1:32767". When I printed the object returned by Connector.open(), I found this :-
com.sun.cldc.io.j2me.datagram.Protocol@1a4cfaaa
This does not appear to be the same as javax.microedition.io.Connection (which is an interface anyway). datagram.Protocol implements DatagramConnection.
Now can anyone help as to how to fix this problem? Or just show me sample code to open a simple datagram connection (UDP) and associate with InputStream object.
Thanks,
SM.

