• Post Reply Bookmark Topic Watch Topic
  • New Topic

total newby question, please help  RSS feed

 
simon hargreaves
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Help,
I am a total newby to Java. Even my first attempts won't work, I am working from a book, according to the book my code should work, but I get the following error.
"Exception in thread "main" java.lang.NoClassDefFoundError:" followed by my filename.
If anyone can help I'd be in yer debt forever, its driving me nuts !
 
Chris Mathews
Ranch Hand
Posts: 2712
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a very common problem, even for experience developers. J2EE packaging is a sticking point for many people and the difference in Classloading between Application Servers does not help.
However, for us to help, you will need to fill us in on more details. What are you trying to do? What have you done? What Application Server are you using? How is your component(s) packaged?
 
simon hargreaves
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Chris,
I have installed J2EE onto my W2K server, I couldn't find a classpath string in autoexec.nt, W2k doesn't have autoexec.bat.
Here's my code, it won't run :
public class Variables
{
public static void main(String[] args)
{
// Declare and initialise each variable type
char chr = 'M';
String str = "Java 2 in easy steps";
int num = 12345;
// Note float declarations followed by 'f'
float dec = 7f;
boolean flg = false;
// Display the values stored in the variables
System.out.println("Character is " + chr);
}
}

It should print the contents of just the one variable for now, but when I try to run it I get the "error in thread "main"" error which I r5eported earlier. To stress, these are my first steps in java so if I seem pretty dumb, forgive me please.
Simon
 
sandy gupta
Ranch Hand
Posts: 228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Boss if u are getting a classnotfound exception then its more like a classpath issue rather than the code itself.
Put the compiled class in a directory and then add that directory to the classpath when u run the class or put the package in a directory and put the base folder of the package in the classpath before u run. That will take care of that.
I hope that makes sense. Please read some initial documentation on classpath to get the fundamentals of how things work and it will be a smooth ride after that.
 
simon hargreaves
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sandy,
Please help, I am running Win2K server which doesn't have autoexec.bat, but has autoexec.nt, others tell me I should set environment variables. I also put this in general java(Beginners) section, in fact I put it in here by mistake. I am now desparate for a straight answer from someone (Anyone) Of course I have read the basic material, thanks for the condescention (Who cares how its spelt) All I have asked for is a little help in getting the damn thing going. I am totally new to java, but am an experienced C++ prog.
 
Chris Mathews
Ranch Hand
Posts: 2712
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you looked at the J2EE Introduction article that Simon Brown wrote for Javaranch a couple months back? If not, here is the link: Introduction to the Java 2 Platform, Enterprise Edition (J2EE).
 
Rufus BugleWeed
Ranch Hand
Posts: 1551
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Windows family has a system control panel. On the advanced tab is a section for environment variables. This is where to define the class path.
You might try an evaluation copy of www.textpad.com. It has a friendly method of running java programs.
There's more powerful IDEs too. I'm using www.eclipse.org.
Sometimes mastering an IDE and a language at the same time is too big a mountain. In this case textpad is real simple.
java.sun.com has a free java tutorial that's real decent.
If you are an experienced c++ programmer, the book A Programmer's Guide to Java Certification - A comprehensive Primer is an excellent language reference manual.
There's some java college deal on this site too.
I think they call it the cattle drive.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!