NoClassDefFoundError when doing a GUI which uses MVC architecture.

I'm trying to do a GUI using MVC architecture. I'm using 4 classes to do this, these comprise the driving Application class (Sketcher) and then the three MVC (SketchModel,SketchView,SketchFrame respectively) classes (as descibed in 'Ivor Horton's Beginning Java 2'. The Application class compiles fine but when I run it, it throws a 'NoClassDefFoundError'. The Application class has methods to return the 3 MVC classes.

I've tried finding out about this error but all advice I've found points to things like typos in the constructor of the class/class definition. I changed the init() method to a constructor as I thought this may be causing the problem but this didn't work.

I've included the code for the classes as I don't really know how to tackle this problem.
Any help/insights would be most appreciated.


   This is the code (without the import statements) for the Application class:-


public class Sketcher
{
      public static void main(String[] args)
      {
            
                  theApp = new Sketcher();// Create the application object...      
                  theApp.init();            //...and intitalise it
            
      }
      
      public void init()
      {
            
                  view = new SketchView(this); //create the view
                  window = new SketchFrame("Sketch", this);
                  Toolkit theKit = window.getToolkit();
               
                 // Other Code left out here
                }

}


The constructor for the View class 'SketchView is as follows

public SketchView(Sketcher theApp)
      {
            // Get reference to app
            this.theApp=theApp;
            
            // Get reference to the Model via the App
            SketchModel Model=theApp.getModel();
      }


The constructor for the Controller class 'SketchFrame' is as follows
public SketchFrame(String title, Sketcher theApp)
{

            setTitle(title);
            this.theApp=theApp;

            // Create Model
            SketchModel model=new SketchModel();

            // Make TreeMaps using method on Model
            String name=new String("Variable Region 1");

            // Set TreeMap vr_start in the view
            theApp.view.vr_start=model.getVrStart();
            
            
            setDefaultCloseOperation(EXIT_ON_CLOSE);
}



The code for the Model class is as follows:-


class SketchModel extends Observable
{


public SketchModel()
      {
// Code here makes a TreeMap

                 }
                TreeMap getVrStart(){ return vr_start;}

}

patelajkAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

zzynxSr. Software engineerCommented:
>> theApp = new Sketcher();

I guess that should be

   Sketcher theApp = new Sketcher();
zzynxSr. Software engineerCommented:
>> when I run it, it throws a 'NoClassDefFoundError'
complaining about which of your 4 classes?
Post the stack trace of this error.
zzynxSr. Software engineerCommented:
Other remark:

[1]
You create the SketchModel in the SketchFrame
>> SketchModel model=new SketchModel();

Do you pass that to Sketcher afterwards?

[2] In SketchView I read:
>> SketchModel Model=theApp.getModel();

Is this the model you created in [1]?
If it is, it will be null at the above line since you create the View before the Frame

>> view = new SketchView(this); //create the view
>> window = new SketchFrame("Sketch", this);





Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

patelajkAuthor Commented:
The error is:

Exception in thread "main" java.lang.NoClassDefFoundError:Sketcher/java

zzynxSr. Software engineerCommented:
How do you (try to) run it? At the DOS prompt? Or via an IDE?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
patelajkAuthor Commented:
At the DOS prompt, I thought it might be a classpath problem but all my classes are the same directory.
patelajkAuthor Commented:
>>You create the SketchModel in the SketchFrame
>>>> SketchModel model=new SketchModel();

>>Do you pass that to Sketcher afterwards?

I see what you mean, I should either pass the Model from SketchFrame (the Controller) to Sketcher(the Application) or I should create the Model in the Application itself.
InNoCenT_Ch1ldCommented:
can u post the exceptions here?
InNoCenT_Ch1ldCommented:
i mean the stack trace
zzynxSr. Software engineerCommented:
>> I thought it might be a classpath problem but all my classes are the same directory.
I think it is a classpath problem.
Have a look at the examples at http://mindprod.com/jgloss/classpath.html
CEHJCommented:
Your code is missing crucial class and instance variables. Horton appears to declare his at the end of the code (a bad idea IMO):

http://www.scils.rutgers.edu/~muresan/202_AdvJava/Horton/Chapter19/Sketcher/1.%20Defining%20a%20Status%20Bar/Sketcher.java
patelajkAuthor Commented:
It was a classpath problem after all. Thanks for all your help it really makes a difference.
CEHJCommented:
>> Your code is missing crucial class and instance variables.

Actually they must have been there originally or it wouldn't have compiled ;-)
patelajkAuthor Commented:
They were there yes, sorry I should have said when I put in the code for Sketcher '   // Other Code left out here' I should have included all the code for Sketcher instead. Sorry for confusing things.

zzynxSr. Software engineerCommented:
Thanks
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.