Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 181
  • Last Modified:

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();
    }
  }
}

 
0
Zadel
Asked:
Zadel
  • 4
  • 2
  • 2
  • +4
1 Solution
 
msterjevCommented:
add the line at beggining:

import java.awt.event.*;
0
 
ZadelAuthor Commented:
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.
0
 
msterjevCommented:
Instantiate:

pieces=new Checker[24];

 into the init method!
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
ZadelAuthor Commented:
Still not working.  :(
0
 
membershCommented:
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)
:-)
0
 
contactdraviCommented:
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
0
 
ZadelAuthor Commented:
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.
0
 
girionisCommented:
 The classpath is the path that the JVM uses to find the classes needed to run your application. If one class is missing then you will get the error you are getting. YOu need to have the "Checker" class in your classpath in order for the applet to work.

  It woudl be good to try it at the appletviewer first but any how... Here is what I sugegst you do:

Copy your html file with the applet, the Checker.class and Proj5.clas files under a web application. Please have both of the class files in the same sudirectory. Try to load the html file and tell us the error message you are getting (if any). I just tried it and it works fine (apart from null pointer exception errors, look at msterjev suggestions for those).
0
 
gloginCommented:
run your program with java -classpath ".;" (dos mode) or ".:" in unix mode
0
 
ZadelAuthor Commented:
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....
0
 
SpideyModCommented:
A request for deletion has been made.  Experts, you have 72 hours to object.

SpideyMod
Community Support Moderator @Experts Exchange
0
 
girionisCommented:
 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.
0
 
SpideyModCommented:
Points awarded.

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 2
  • 2
  • +4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now