View Full Version : Exception in thread "main" java.lang.NoClassDefFoundError
pnz999
Jan 31, 2003, 05:40 PM
java error in mac os x.2.3 terminal.
I get this error "Exception in thread "main" java.lang.NoClassDefFoundError" when I try to run my *.class file under Terminal? What should I do?
I think I compile it correctly cause it pop up a *.class file with no error comment
import javax.swing.JOptionPane;
public class circle
{
public static void main(String[] args)
{
String input = JOptionPane.showInputDialog ("Please enter the radius");
double rad = Double.parseDouble(input);
double area = Math.PI*2*rad;
double cir = Math.PI*Math.pow(rad,2);
System.out.println("The area is " + area + ".");
System.out.println("The circumference is " + cir + ".");
}
}
cubist
Jan 31, 2003, 06:06 PM
Here are the correct commands to use. Note that on the "java" command, which runs the .class file, you do NOT specify "circle.class":
javac circle.java
java circle
The program works. However, this is not really a good way to do things, partially using Swing and partially using text input-output. After it displays its output, you have to break (with ctrl-C) to get back to the system prompt.
What I usually do is have main just construct the outer class:
public static void main( String args[] ) {
circle c = new circle();
}
Then have the constructor for class circle do all the work:
public circle() {
etc.
}
But Swing requires a little more complexity in application design. Keep learning!
macktheknife
Jan 31, 2003, 06:10 PM
I ran your program just fine. After you've compiled it, type the following (without the quotes): "java circle". Don't put ".class" after "circle."
It should work--let me know if it doesn't.
pnz999
Feb 1, 2003, 12:00 PM
It work! Thanks
I just need to be in the same directory as my *.java and *.class files.
BTW, is it possible to do C++ programming in a mac? can i still use Terminal?
and also How can I tell what version of Java in on my machine(10.2.3 / G4 MDD)? and Java on a Mac is the same as Sun's Java?
cause current Sun's Java version is 1.4.1_01
bousozoku
Feb 1, 2003, 12:15 PM
You can definitely do C++ programming within the terminal.
type cc -o programmefile programsource for C, C++, and Objective-C.
Then, once it compiles successfully, you may run your programme by typing ./programmefile
macktheknife
Feb 1, 2003, 03:47 PM
Originally posted by pnz999
BTW, is it possible to do C++ programming in a mac? can i still use Terminal?
Yes you can. Check out this thread for more info:
C++ Programming on OS X (http://forums.macrumors.com/showthread.php?s=&threadid=16843)
and also How can I tell what version of Java in on my machine(10.2.3 / G4 MDD)? and Java on a Mac is the same as Sun's Java?
cause current Sun's Java version is 1.4.1_01
Type (again, without the quotes) "java -version" in Terminal. OS 10.2.3 currently comes with Java 1.3.1. Apple currently has a beta version of Java 1.4 for OS X, and it should hopefully be released soon.
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.