• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Java problem: Don't know how to compile with the sdk

import java.net.*;
import java.io.*;


public class IPFinder
{
public static void main(string[] args) throws IOException
{
String host;
BufferedReader input =
new BufferedReader( new InputStreamReader(System.in));

System.out.println("\nEnter host name: ");
host = input.readLine();
try
{
InetAddress address=
InetAddress.getByName(host);
System.out.pringln("IP Address: " + address);
}
catch (UnknownHostException e)
{
System.out.println("Could not find " + host);
}
}
}
java -classpath TCPServer.java runs with no problem

java TCPServer replies
"Exception in thread "main" java.lang.NoClassDefFoundError: TCPServer


I am sure I'm compiling this wrong... I have the j2sdk-1_3_1_15-windows-i586.exe installed and I'm just copying off of handouts... can someone tell me what I'm doing wrong?
 
1) "java -classpath TCPServer.java" should produce an error.

2) The "java" command runs compiled .class class files
The "javac" command compiles java .java source files.

3) Where is the TCPServer.java / .class file? You showed us the source for another class, IPFinder.
 
I dunno what I'm doing.... I just need to get the file above, running, hell or high water in a command window by 7:00...... I know nothing about java... could you guys please just tell me what to do 😉 ?
 
Originally posted by: acemcmac
I dunno what I'm doing.... I just need to get the file above, running, hell or high water in a command window by 7:00...... I know nothing about java... could you guys please just tell me what to do 😉 ?
If you don't know anything about java, why are you responsible for working with java source files?
 
Originally posted by: znaps
Type "javac IPFinder.java" and see if that creates a IPFinder.class file in the same directory.

negative, even with the file named IPFinder.java.

Originally posted by: Kilrsat
Originally posted by: acemcmac
I dunno what I'm doing.... I just need to get the file above, running, hell or high water in a command window by 7:00...... I know nothing about java... could you guys please just tell me what to do 😉 ?
If you don't know anything about java, why are you responsible for working with java source files?

good question, ask my prof. He wants this by 7
 
Working from memory - try

javac TCPServer.java, when you're in the same directory as the file. You may need to edit your PATH for access to the javac binary. Or

c:\jdk1.3.1_15\bin\javac path\to\your\file\TCPServer.java

and tell us the error.
 
type "javac IPFinder.java" and see if that creates a IPFinder.class file in the same directory.

type it exactly as I said, not "javah..", not "javac -classpath" and not "java ..."


Then type "dir" and see if there is an "IPFinder.class" file.

If there is, type "java IPFinder"

 
Are you sure the name of the file and the name of the class are the same? As in, for the class IPFinder you should have a file called IPFinder.java.

Also, time to dump the way old jdk. It's two major versions old 😛
 
Originally posted by: znaps
type "javac IPFinder.java" and see if that creates a IPFinder.class file in the same directory.

type it exactly as I said, not "javah..", not "javac -classpath" and not "java ..."


Then type "dir" and see if there is an "IPFinder.class" file.

If there is, type "java IPFinder"

HOORAYYYY THE DAY IS SAVED!!!!
 
Back
Top