• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

compile from the terminal ok but error running from terminal

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy (I've always wanted to say that (and mean it) from some strange reason),
I'de first like to say that this site is awsome, I love the theme and with all these java experts around, I am wondering if I can hang my hat for a little while (ok, enough with the silliness(SP?), I am aware that it can annoy some grumpy folks after a while :-)).
Ok, down to business. I have the JDK 5.0 release 7 and I have it installed in just one folder away from my lettered drive on Windows XP, for example; (F:\Java). When I edit source code through a text editor and then compile it through the terminal it seems to compile fine and I get a pretty little class file afterwords. However, the trouble comes when I try and run the program with the 'java' command. I get a weird error? message. It reads as follows:

Exception in thread "main" java.lang.NoClassDefFoundError: helloWorld

Of course in this example I used helloWorld as the name of the class that I was trying to run. It's not the code, at least I don't think so because my Mac runs the same code on the same JDK (just a different release, release 5) perfectly. This is not just isolated to one incedent either, it happens every time.
Because of my problem (well not the entire reason, I love eclipse), I am using eclipse and ofcourse with eclipse, everything works perfectly but it just erks me that I can't run my classes/apps from the terminal on my wondows machine. I also have a windows laptop but I am affraid to edit the path variables on that machine as well for fear that I might screw it up in the same way. I am new to the Windows Environment, having come back to windows because of .NET around a year ago but other than that I am used to *nix platforms such as Linux and OS X so my knowledge of windows is slim. Does anyone know what's wrong? I tried to look up: java.lang.NoClassDefFoundError in Java in a Nutshell (latest edition) and I can't seem to find anything about it, as if it doesn't exsist?
Please excuse my ignorance, I am brand spanking new to Java but not to programming (some C (old school, lol I'm 25y/o, what am I doing talking about old school?), .NET, Python and ActionScript) If anyone could help, I would be very greatful and extremely happy. (I'll have my itch scatched, you know the one the is starting to sting a little.) No really, I would be very greatful for a fix to my seemingly small but notoriously big problem. Thanks in advance
You can contact me through this e-mail. learningjava@airspoon.com

Yours Truly,
--Matt
 
Ranch Hand
Posts: 2410
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Most likely you have a problem with your CLASSPATH.

You need to make sure that the directory containing your .class file is in your CLASSPATH.

Try this

java -cp . helloWorld

Are you sure the name of the class is helloWorld?

Remember that you have to have the exact name.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Matt, welcome to the forums.

Try typing in "NoClassDefFoundError" in Google. You'll find that it's one of the pitfalls that almost all new Java programmers hit.

In addition to that, in my signature (below this message) there is a link to The Java Tutorial. It's a very useful online tutorial, and the "Hello World" example there explains exactly what this error means and what you have to do about it.

Have fun with Java.
 
Matthew Hartman
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys,
Keith, so my workspace (whichever that may be) has to be named in my CLASSPATH?

Jesper, I am still going through the links in your signature. I still havent found anything on the issue at hand (but I have just looked through briefly.) I got it to work by putting my workspace or the folder containing my source and class file in my CLASSPATH variable, However, I had to delete the the package name in the source file in order for it to work.

--Matt
 
Farmers know to never drive a tractor near a honey locust tree. But a tiny ad is okay:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic