View Full Version : Annoying error
rross46
05-16-2006, 08:14 PM
Hi. I was going over some old Java stuff i had. I was trying to run a simple client server program. When i try to run each i get the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: MiniServer
Exception in thread "main" java.lang.NoClassDefFoundError: MiniClient
Any ideas as to why i am getting this? It compiles ok, i am clueless as to why i am getting this error. The code seems ok, it was ripped from example stuff i got from a lecturer.
Any chance the class names are incorrect?
Post your code, it might help sort things out.
Melon00
05-17-2006, 02:54 PM
Also, you created the classes, make sure that you are including it in the file that needs to use it.
rpgfan3233
05-19-2006, 04:18 AM
Perhaps your command line needs to be altered:
java -cp . MiniClient
to specify the current directory rather than the default JDK directory?
rross46
06-19-2006, 02:07 PM
package org.me.server;
/**
*
* @author jean
*/
import java.io.*;
import java.net.*;
public class MiniServer {
public static void main(String args[]) throws IOException {
if (args.length != 1) {
System.out.println("Usage: " + "java MiniServer portnumber");
System.exit(1);
}
int portnum = Integer.parseInt(args[0]);
ServerSocket sock = null;
try {
sock = new ServerSocket(portnum);
} catch (IOException e) {
System.out.println("Could not listen on port: " + portnum + ", " + e);
System.exit(1);
}
System.out.println("Now listening at port " + portnum);
Socket clientSocket = null;
try {
clientSocket = sock.accept();
} catch (IOException e) {
System.out.println("Accept failed: " + portnum + ", " + e);
System.exit(1);
}
// Create an input stream on the socket
InputStream anInputStream = clientSocket.getInputStream();
// Create an input stream reader on the client
InputStreamReader anInputStreamReader = new InputStreamReader(anInputStream);
// Create a buffered reader for efficiency
BufferedReader input = new BufferedReader(anInputStreamReader);
// Create an output stream on the socket
OutputStream anOutputStream = clientSocket.getOutputStream();
// Create a print writer on the output stream
PrintWriter output = new PrintWriter(anOutputStream);
System.out.println("Connection established.");
int lineCount = 0;
String line = input.readLine();
while (line != null) {
System.out.println("Server received : " + line);
lineCount = lineCount + 1;
output.println(line.length() + " characters");
output.flush();
line = input.readLine();
}
} // End of main
} // End of MiniServer
/*
* MiniClient.java
*
* Created on 21 November 2005, 11:19
*
* To change this template, choose Tools | Options and locate the template under
* the Source Creation and Management node. Right-click the template and choose
* Open. You can then make changes to the template in the Source Editor.
*/
package org.me.client;
/**
*
* @author jean
*/
import java.io.*;
import java.net.*;
public class MiniClient {
static BufferedReader keyboard = new
BufferedReader(new InputStreamReader(System.in));
public static void main(String args[]) throws java.io.IOException {
if (args.length != 2) {
System.out.println("Usage: " + "java MiniClient hostname portnumber");
System.exit(0);
}
int portnum = Integer.valueOf(args[1]).intValue();
Socket sock = new Socket(args[0],portnum);
// Create an input stream on the socket
InputStream anInputStream = sock.getInputStream();
// Create an input stream reader on the inputstream
InputStreamReader anInputStreamReader = new InputStreamReader(anInputStream);
// Create a buffered reader for efficiency
BufferedReader input = new BufferedReader(anInputStreamReader);
// Create an output stream on the socket
OutputStream anOutputStream = sock.getOutputStream();
// Create a print writer on the output stream
PrintWriter output = new PrintWriter(anOutputStream);
System.out.println("type some characters then" + " return");
String line = keyboard.readLine();
while (line != null) {
output.println(line);
output.flush();
line = input.readLine();
System.out.println("Client received : " + line + " back from the Server ");
System.out.println();
System.out.println("Type some characters followed by the enter key");
line = keyboard.readLine();
}
} // End of main
} // End of class MiniClient
Still getting same error. PRoblem with me is that I aint too sure with java. Not used with it, using command line to do stuff, this is me trying to get more sure with it.
C:\Program Files\Java\jdk1.5.0_03\bin\javabeans\accountbeansstuff\MiniClient\bui
ld\classes\org\me\client
This is the path to the .class file. I was just typing java MiniClient localhost 3001 (as specified in the notes I am using). I did it again and got another error:
Exception in thread "main" java.lang.NoClassDefFoundError: MiniClient (wr
e: org/me/client/MiniClient)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Any idea's?. Sorry to come across all noob, Im not used to java at all, mainly using command line for things, struggling to get my head around it.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.