?
Solved

NoClassDefFoundError

Posted on 2003-02-20
13
Medium Priority
?
180 Views
Last Modified: 2010-03-31
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
Comment
Question by:Zadel
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +4
13 Comments
 
LVL 3

Expert Comment

by:msterjev
ID: 7991875
add the line at beggining:

import java.awt.event.*;
0
 

Author Comment

by:Zadel
ID: 7991915
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
 
LVL 3

Expert Comment

by:msterjev
ID: 7991941
Instantiate:

pieces=new Checker[24];

 into the init method!
0
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 

Author Comment

by:Zadel
ID: 7991960
Still not working.  :(
0
 
LVL 1

Expert Comment

by:membersh
ID: 7991991
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
 

Expert Comment

by:contactdravi
ID: 7992016
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
 

Author Comment

by:Zadel
ID: 7992018
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
 
LVL 35

Accepted Solution

by:
girionis earned 400 total points
ID: 7992611
 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
 

Expert Comment

by:glogin
ID: 7998874
run your program with java -classpath ".;" (dos mode) or ".:" in unix mode
0
 

Author Comment

by:Zadel
ID: 8022948
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
 

Expert Comment

by:SpideyMod
ID: 8173954
A request for deletion has been made.  Experts, you have 72 hours to object.

SpideyMod
Community Support Moderator @Experts Exchange
0
 
LVL 35

Expert Comment

by:girionis
ID: 8173995
 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
 

Expert Comment

by:SpideyMod
ID: 8190970
Points awarded.

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month14 days, 4 hours left to enroll

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question