RMI Casting problems
Hi all,
I'm developing a chatroom with a built-in shorthand feature. The client, an applet, actually accesses 2 RMI serers: chat server and shorthand server. The chat server works fine, using LinkedList's. The shorthand server uses ArrayList (because I read that it was serializable and faster. The server is works fine but I keep getting casting exceptions when I try to accass the shorthand pairs. Both RMI servers have their own port and registry name. Any ideas would b appeciated
Server Code:
--
ArrayList candidates = null;
String abrv;
String wrd;
int ARRAY_NUM=13;
String[] words = new String[ARRAY_NUM];
String[] shorts = new String[ARRAY_NUM];
intthisPort = 3231;
StringthisAddress; // = "192.168.0.3";
Registry registry;// rmi registry for lookup the remote objects.
int index = 0;
String nullString = "~NULL~";
Connection con;
public AbbrvServer(String ab, String wd) throws RemoteException {
abrv = ab;
wrd = wd;
}
.
.
.
while (rs.next()) {
try {
AbbrvServer dummyPair = new AbbrvServer(nullString,nullString);
dummyPair.abrv = rs.getString("abbrv");
dummyPair.wrd = rs.getString("word");
candidate.add(dummyPair);
//candidate.add((AbbrvServer)dummyPair);
//candidates = candidate.w
System.out.println("the abrev '"+dummyPair.abrv + " and " + dummyPair.wrd + " hazs been added");
} catch (Exception ex) {
ex.printStackTrace();
}
} // while
stmt.close();
-
Client code:
--
//RMI and local variables
String serverAddress = "192.168.0.3";
String serverPort = "3231";
String chatPort = "3232";
Registry regChat, regAbrv;
SpazzChatInterface spazzServer;
ArrayList chat = new ArrayList();
ArrayList candidates = new ArrayList();
//ArrayList followers = new ArrayList();
LinkedList members = new LinkedList();
String userName = null; //Get a parameter value
int indentTo = 20;
int startSel, endSel = 0;
Locale thisLocale = new Locale("en","US");//Helps define word boundaries
char cIn;
String wdIn = null;
AbbrvInterface abrvServer;
AbbrvServer abrvPair;
String lstWd;
boolean isWord = false;
.
.
.
stIn = getWord(carrotPos, cIn);
//stIn = getWord(cIn);
candidates = (ArrayList)abrvServer.getCandidates(stIn);
populateAbbrvList();
public void populateAbbrvList() {
abbrvList.removeAll();
// Fill memberlist
predicters.clear();
if (!candidates.isEmpty()) {
for (int j = 0; j < candidates.size(); j++) {
//if (candidates.get(j).instanceof {
try{
// abrvPair = (AbbrvServer) candidates.get(j);
AbbrvServer abrvPair = (AbbrvServer)candidates.get(j);
} catch(java.lang.ClassCastException clE){
try {
AbbrvServer abrvPair = new AbbrvServer("No data ",
"available");
} catch(RemoteException rm) {
System.err.println(rm);
}
System.err.println(clE);
}
/* try{
// abrvPair = (AbbrvServer) candidates.get(j);
abrvPair = (AbbrvServer)candidates.get(j);
} catch(java.lang.ClassCastException clE){
abrvPair.abrv = "No data ";
abrvPair.wrd = "available";
System.err.println(clE);
} */
predicters.addElement("F" + (j + 1) + ": " + abrvPair.abrv +
" - " +
abrvPair.wrd);
}
-
Thanks.
Chris

