• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
zach sycks
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Sri Ram
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
just typed that at the command prompt and got the same error. argh.
 
Abdulla Mamuwala
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
zach sycks
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic