• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Head first java exercise JVM problem

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what the error means is that it cannot find the class file. Make sure that your path is correct
 
Jean-Marc Bottin
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic