class cast exceoption

N

nialltimpson

Could any one spare to seconds to see how im geting a class cast exception
here, ive been beating my head aginst the screen for a good long time now
and geting no where.

import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
import java.util.*;
import javax.swing.*;
import java.math.BigInteger;

public class serverThreadSetup extends Thread implements Runnable{

public static final Vector eCommAttached = new Vector();
public static final Vector clientAttached = new Vector();
public static Socket eCommServer;

private ObjectInputStream in;
private ObjectOutputStream out;

String message;
String eCommMsg;
setupServer serv;

Object input;

//----------------------------------------------------------------------\\
public serverThreadSetup(Socket client) throws IOException{
out = new ObjectOutputStream(client.getOutputStream());
in = new ObjectInputStream(client.getInputStream());
setClient(client);
start();
}
//----------------------------------------------------------------------\\
private Socket client;
public void setClient(Socket client){
this.client = client;
clientAttached.add(this);
}

//----------------------------------------------------------------------//

public Socket getClient(){return client;}
public void run()
{
try{
while (setupServer.isServerUp()){
try{
out.writeObject("connected");
message = (String)in.readObject();
eCommMsg = (String)input;
System.err.println(message);
updateBroadcast(eCommMsg);
}

catch (ClassNotFoundException cnfe) {
System.err.println("CNFE");
}
}
}
catch (IOException ioe) {}
finally{
//close();
}
}

//----------------------------------------------------------------------//

public static void updateBroadcast(Object eCommMsg){

for (int i=0;i<eCommAttached.size();i++){

// the next line is the error.

((serverThreadSetup)eCommAttached.get(i)).updates(eCommMsg);
}
}
//----------------------------------------------------------------------\\
public void updates(Object eCommMsg)
{
try {
System.err.println("here4");
out.writeObject(eCommMsg);
}
catch (IOException ioe) {}
}
//----------------------------------------------------------------------\\
public void close(){
try{if (in!=null)
in.close();}
catch (IOException ioe){}
try{if (out!=null)out.close();}
catch (IOException ioe){}
try{if (client!=null)client.close();}
catch (IOException ioe){}
}
//----------------------------------------------------------------------

}

Im readin in an object, i.e string

Thank you very much who ever decides to help

Niall
 
K

klynn47

To debug I would step through each element of the Vector, and use
getClass().getName() to see what the type of the elements are
 
N

nialltimpson

Yeah just after doing that and I found I wasnt initialising the vector with
the correct element, goes to show things really can be stareing you in the
face and you dont see them. thanks again all.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top