wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Head First Java - probably a really dumb question from the newest newbie ever Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Head First Java - probably a really dumb question from the newest newbie ever" Watch "Head First Java - probably a really dumb question from the newest newbie ever" New topic
Author

Head First Java - probably a really dumb question from the newest newbie ever

zach sycks
Greenhorn

Joined: Dec 18, 2005
Posts: 5
I just worked through this first example in the book and I can't figure out why it issues an error when I try to run it.

public class MyFirstApp {

public static void main (String[] args) {
System.out.println("I Rule!");
System.out.println("The World");
}

}


I saved it as MyFirstApp.java. I compiled it (javac MyFirstApp.java) and it generated MyFirstApp.class. I typed at the command line "java MyFirstApp.class" and it says:

Exception in thread "main" java.lang.NoClassDefFoundError: MyFirstApp/class

So what gives? Any help is gratiously appreciated.
[ December 18, 2005: Message edited by: zach sycks ]

http://sycks.com/educate
Sri Ram
Ranch Hand

Joined: Oct 03, 2005
Posts: 118
I saved it as MyFirstApp.java. I compiled it (javac MyFirstApp.java) and it generated MyFirstApp.class. I typed at the command line "java MyFirstApp.class" and it says:


U have to give "java MyFirstApp" without that .class.

And Hey u can look at
this url for more info on running a Java Prog.
[ December 18, 2005: Message edited by: Sri Ram ]
Abdulla Mamuwala
Ranch Hand

Joined: Jan 09, 2004
Posts: 225
Dear Zach,

Inorder that your program should execute just type the following command,
java MyFirstApp
You dont need the dot class extension.
Have fun
[ December 18, 2005: Message edited by: Abdulla Mamuwala ]
zach sycks
Greenhorn

Joined: Dec 18, 2005
Posts: 5
just typed that at the command prompt and got the same error. argh.
Abdulla Mamuwala
Ranch Hand

Joined: Jan 09, 2004
Posts: 225
Is your class file in the same directory from where you are executing your java command. That is if you have your .class file in say C:\MyPrograms, change directory to that particular directory and than execute your java command i.e, C:\MyPrograms\java MyFirstApp
Good Luck
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by zach sycks:
just typed that at the command prompt and got the same error. argh.

Are you getting exactly the same error? Or is the the same error without "/class" at the end?

See this thread.
[ December 18, 2005: Message edited by: marc weber ]

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
zach sycks
Greenhorn

Joined: Dec 18, 2005
Posts: 5
Checking out that thread, looks like the right thing so far! It is indeed the same error, but without /class as you've pointed out.

Thanks!
zach sycks
Greenhorn

Joined: Dec 18, 2005
Posts: 5
Per the other thread, I typed:

java -cp . MyFirstApp and that took care of it!

Also, if I read the prior thread correctly, I needed to put a . in my CLASSPATH for Windows XP. I did that as well, we'll see what happens.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Head First Java - probably a really dumb question from the newest newbie ever
 
Similar Threads
Can't get MyFirstApp working
MyFirstApp
Head First Java confusion
Can not run a simple program
2 questions about classpath