Link to home
Start Free TrialLog in
Avatar of Zadel
Zadel

asked on

NoClassDefFoundError

I am new to Java programming, and I seem to still be struggling with the OOP nature of it.  I figure that has something to do with the error that I am currently getting.

Basically, this program creates an applet that displays a checker board with 24 pieces on it.  Eventually, more will be able to be done with the individual pieces (thus, my reasoning for storing all of the data on each in an array).

When I try running this program, I am getting a NoClassDefFound Error.  Any thoughts on what I can do to fix the problem?

Also, I know that as the code is now, the Checkers will not show up.  That's the next step after this.  Thanks.


import java.awt.*;
import java.applet.*;

class Checker{
    String color;
    int crowned;
    int xloc;
    int yloc;
  public Checker(){
    color=null;
    crowned=0;
    xloc=0;
    yloc=0;
  }
}

public class Proj5 extends Applet implements Runnable{
  Thread kicker;
  int x0,y0,x,y;
  int color=1;
  Checker[] pieces = new Checker[24];
  public void paint(Graphics g){
    for(int i=0;i<8;i++){
      for(int j=0;j<8;j++){
        color=color*-1;
        if(color==1){
          g.setColor(Color.blue);
         }
        if(color==-1){
          g.setColor(Color.orange);
        }
        g.fillRect(x,y,40,40);
        x=x+40;
      }
      color=color*-1;
      x=x0;
      y=y+40;
    }
  }

  public void init(){
    x0=20;
    y0=20;
    x=x0;
    y=y0;
    int blah=1;
    int num=0;
    for(int i=0;i<8;i++){
      for(int j=0;j<8;j++){
        blah=blah*-1;
          if((blah==1)&&(i<3)){
            pieces[num].xloc=x+10;
            pieces[num].yloc=y+10;
            pieces[num].color="red";
          }
          if((blah==1)&&(i>4)){
            pieces[num].xloc=x+10;
            pieces[num].yloc=y+10;
            pieces[num].color="black";
          }
        }
        x=x+40;
        num++;
      }
    blah=blah*-1;
    x=x0;
    y=y+40;
  }

   /*
    addMouseListener(new MouseAdapter(){
      public void mouseClicked(MouseEvent e){

  }*/

  public void run(){
    while(kicker!=null){
      repaint();
    }
  }
}

 
Avatar of msterjev
msterjev

add the line at beggining:

import java.awt.event.*;
Avatar of Zadel

ASKER

Hmm...  That probably will be needed when the mouse code is activated.

I realized that I should clarify the error a bit more.  I am getting  Exception: java.lang.NoClassDefFoundError: Checker

Thanks.
Instantiate:

pieces=new Checker[24];

 into the init method!
Avatar of Zadel

ASKER

Still not working.  :(
Are u using appletViewer to view the applet ? U will get NoClassDefFoundError if there is no '.' in ur CLASSPATH. So add it. i could go beyond that, but got java.lang.NullPointerException
        at Proj5.init(Proj5.java:52)
:-)
coud you make sure that the folder where Checker.class resides ( i hope the Cheker.class is in the same folder , where you are ruinning) is in the path & classpath.
in Windows NT
PATH=;.;%PATH%;
in Unix
export PATH=:.:$PATH
Avatar of Zadel

ASKER

My CLASSPATH?  Like I mentioned, I am quite new to Java programming.  Where is CLASSPATH?  As to your first question, no, I am not using an appletViewer as I do not yet have one (I am remotely connecting into a UNIX machine--no graphics).  Thus, I have set it up so that I can view the applet from a webpage.
ASKER CERTIFIED SOLUTION
Avatar of girionis
girionis
Flag of Greece image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
run your program with java -classpath ".;" (dos mode) or ".:" in unix mode
Avatar of Zadel

ASKER

I'd had both classes in the same file.  When I separated them, I still had trouble, so I adjusted the classpath and really made a mess of things.  However, once I moved it all into a new folder, it worked fine.  *shrugs*

Now, I will start to work on those NullPotinerExceptions....
A request for deletion has been made.  Experts, you have 72 hours to object.

SpideyMod
Community Support Moderator @Experts Exchange
 The original question was regarding the NoClassDefFoundError and I can see clearly that the error is solved (comment from Zadel on 02/25/2003 09:09PM PST):

"I'd had both classes in the same file.  When I separated them, I still had trouble, so I adjusted the classpath and really made a mess of things.  However, once I moved it all into a new folder, it worked fine.  *shrugs*"

  I suggest he lets us know who the points should be allocated to, otherwise I suggest the points are split between all the participants.
Points awarded.

SpideyMod
Community Support Moderator @Experts Exchange