Reputation: 11
I wrote a chat java application that use sockets. I have three Netbeans project, 1. Client side, 2. Server side and 3.Tester. projects Hierarchy
In the Tester I want to start a Thread for Server class.
public class Tester {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws Exception {
//for (int i = 0; i<args.length; i++) {
final Class clazz = Class.forName("ServerSide");
new Thread(new Runnable() {
@Override
public void run() {
try{
Method main = clazz.getMethod("main", String[].class);
main.invoke(null, new Object[]{});
} catch(Exception e) {
// improper exception handling - just to keep it simple
}
}
}).start();
// }
}
}
but I always obtain ClassNotFoundException. Is the path wrong? Thanks a lot. Sorry for the stupid question!
Upvotes: 0
Views: 763
Reputation: 302
You must include also the package into the required classname parameter:
Class.forName("serverside.ServerSide");
Upvotes: 2