*
The moose likes Beginning Java and the fly likes Head first java exercise JVM problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Head first java exercise JVM problem" Watch "Head first java exercise JVM problem" New topic
Author

Head first java exercise JVM problem

Jean-Marc Bottin
Greenhorn

Joined: Feb 03, 2004
Posts: 11
Hi,
I just started to do some java and I just bought "Head First Java.
While I was testing the pool Puzzle exercise of the chapter 4 I had a error from (I think) the JVM.
I can compile (I still think) because when I do, javac Puzzle4.java, I get a Puzzle4.class in my folder. So I think the compilation was successful.
When I want to execute the program: java Puzzle4, I get the following message:
Exception in thread "main" java.lang.NoClass.DefFoundError: Puzzle4
What does this mean?
Here is my code:
public class Puzzle4
{
public static void main (String[] args)
{
Puzzle4b[] obs = new Puzzle4b[6];

int y = 1;
int x = 0;
int result = 0;

while ( x < 6)
{
obs[x] = new Puzzle4b();
obs[x].ivar = y;
y = y * 10;

x = x + 1;
}

x = 6;
while ( x > 0 )
{
x = x - 1;
result = result + obs[x].doStuff(x);
}

System.out.println("result " + result);
}
}
class Puzzle4b
{

int ivar;
public int doStuff( int factor )
{
if ( ivar > 100 )
{
return ivar * factor;
}
else
{
return ivar + ( 5 - factor );
}
}
}
Can somebody tell me what is going on in the java engine?
Thanks,
Jean-Marc
David Maddox
Greenhorn

Joined: Feb 25, 2004
Posts: 12
what the error means is that it cannot find the class file. Make sure that your path is correct
Jean-Marc Bottin
Greenhorn

Joined: Feb 03, 2004
Posts: 11
Thanks for the answer, it makes more sense. One more question. By path you mean the path and classpath or only the classpath, because I did'nt have any trouble with the exercises on the previous chapters.
Jean-Marc
Shawn Paige
Greenhorn

Joined: Feb 26, 2004
Posts: 1
Be sure that the classpath environment variable includes the location of the class file you are trying to execute. You might want to add the current working directory, or "." to your classpath.
HTH.
Shawn
Jean-Marc Bottin
Greenhorn

Joined: Feb 03, 2004
Posts: 11
As bizarre as it sounds, I managed to make the code to run.
I had previously set the classpath with: c:/Sun/AppServer/jdk/lib/tools.jar
I deleted this for the system (Windows 2000 OS) and only kept the PATH : C/Sun/AppServer/jdk/bin and it works.
I still very confused ad I am worry that in a near futur I will have to modified the PATH and CLASPATH again, while I still ahve understand it properly. On the Sun web site, the infos are not clear at all. I have installed J2EE instead of JSE. Most of the infos could be found for JSE but J2EE I did not find anything clear at all.
Does somebody know why?
J-M
 
 
subject: Head first java exercise JVM problem