help with Java

  • Katushai
  • Graduate
  • Graduate
  • User avatar
  • Posts: 152

Post 3+ Months Ago

I recently started reading a book on Java. I installed the Sun One Studio compiler, Community Edition. Ive had a problem with all my java programs.

Basically, i can compile, build, and execute the program inside the compiler, with its own i/o box. But, when i try to run the program outside of the compiler, i get an error. I typed "java robot" and this is the error i got:

Code: [ Select ]
Exception in thread "main" java.lang.NoClassDefFoundError: robot


and the program never executes. I tried running it in an applet, and the same problem occurred. So, i tried running any normal java program, and it worked. so, whats my problem? im sorry if this question is novice, im new to java. i think it might be the compiler...? thanks for any help.
  • katana
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 2391
  • Loc: Edinburgh, Scotland

Post 3+ Months Ago

First off, are you executing the command in the same directory as where your robot.class file is found? Often when you compile files using an advanced IDE, they hide your class/exe files away in some folder, for instance "bin" or "debug" etc.
  • Katushai
  • Graduate
  • Graduate
  • User avatar
  • Posts: 152

Post 3+ Months Ago

yep, i went there and typed that in the exact folder that my .class file was in
  • katana
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 2391
  • Loc: Edinburgh, Scotland

Post 3+ Months Ago

And, you're sure your class is called "robot", i.e. all lower case? The "java" command's arguments are case sensitive, i.e. "java Robot" != "java robot".
  • Katushai
  • Graduate
  • Graduate
  • User avatar
  • Posts: 152

Post 3+ Months Ago

yep, and just to be sure, i tried again. still didnt work
  • katana
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 2391
  • Loc: Edinburgh, Scotland

Post 3+ Months Ago

What's the rest of the error message? Or is it just the one line?
  • Katushai
  • Graduate
  • Graduate
  • User avatar
  • Posts: 152

Post 3+ Months Ago

its just that one line
  • katana
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 2391
  • Loc: Edinburgh, Scotland

Post 3+ Months Ago

Try running the following command:
Code: [ Select ]
java -cp . robot
  • Katushai
  • Graduate
  • Graduate
  • User avatar
  • Posts: 152

Post 3+ Months Ago

wow! awesome! thanks so much dude!
  • Katushai
  • Graduate
  • Graduate
  • User avatar
  • Posts: 152

Post 3+ Months Ago

one more question--- how do i get it to work in an applet?
  • katana
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 2391
  • Loc: Edinburgh, Scotland

Post 3+ Months Ago

You'll need to run the applet from an applet viewer. Probably the easiest way to do this is to just create a simple HTML file that invokes the applet.
  • Katushai
  • Graduate
  • Graduate
  • User avatar
  • Posts: 152

Post 3+ Months Ago

thanks
  • Nasoma
  • Beginner
  • Beginner
  • User avatar
  • Posts: 42
  • Loc: Pennsylvania

Post 3+ Months Ago

Quote:
Try running the following command:
Code: [ Select ]
java -cp . robot


So what exactly is the '-cp .' for? Just curious.
  • katana
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 2391
  • Loc: Edinburgh, Scotland

Post 3+ Months Ago

It overrides the Java Classpath environment variable. Java looks for an environment variable named "CLASSPATH". Usuallt this path contains the "." character which tells the JVM to look at the current directory when running. Using -cp sets a temporary classpath, and the "." tells it which directory to use (in this case, the current directory).

Post Information

  • Total Posts in this topic: 14 posts
  • Users browsing this forum: No registered users and 27 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.