Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2011
    Posts
    93
    Rep Power
    0

    Default Not Understanding: NoClassDefFoundError

    Hello. I am writing a program (called OutlineMosaic) to make a visual display. OutlineMosaic calls on methods in a program called Mosaic. I have already written and compiled Mosaic and have called its methods successfully from another program. OutlineMosaic and Mosaic both reside in the same folder. I have successfully compiled OutlineMosaic without any errors.

    When I run OutlineMosaic (using command prompt) I get the following error message:
    NoClassDefFoundError: Mosaic$1
    at Mosaic.Open(Mosaic.java:70)
    at OutlineMosaic.main(OutlineMosaic.java:10)

    So I don't get this. I know Mosaic exists, I know where it exists, I have successfully called it before, and the program calling Mosaic compiled without any problems. Yet, now java seems to be looking for something called Mosaic$1, and is not finding it. I have no idea what Mosaic$1 is.

    Can anyone help me understand this? Thanks.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,742
    Rep Power
    19

    Default Re: Not Understanding: NoClassDefFoundError

    Looks like Mosaic has an anonymous inner class declared in the code somewhere (like an anonymous listener).
    The compiler will have taken this anonymous class and created a compiled class for it call '<classname>$<anonymous number>.class'.
    In your case 'Mosaic$1.class'.
    So you're missing a class file.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    Join Date
    Mar 2011
    Posts
    93
    Rep Power
    0

    Default Re: Not Understanding: NoClassDefFoundError

    Hello. Thanks for your reply. If I remember correctly, I had previously removed a file called Mosaic$1 from this same folder, because I didn't recognize it. So I will try and recompile the Mosaic program again. Hopefully, that will restore the deleted Mosaic$1 file.

    Sorry for my ignorance: what is an "anomynous" class?

    Quote Originally Posted by Tolls View Post
    Looks like Mosaic has an anonymous inner class declared in the code somewhere (like an anonymous listener).
    The compiler will have taken this anonymous class and created a compiled class for it call '<classname>$<anonymous number>.class'.
    In your case 'Mosaic$1.class'.
    So you're missing a class file.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,742
    Rep Power
    19

    Default Re: Not Understanding: NoClassDefFoundError

    You see them in things like Swing quite a lot.
    Java Code:
    Button b = new Button("My Button");
    b.addActionListener( new ActionListener() {
       public void actionPerformed(ActionEvent ev) {
          // do something
       }
    });
    That ActionListener is an anonymous inner class. That is, it's a class with no name, defined in the place it is actually used.
    That would create a $n class file.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Understanding 'static' a little more
    By salmontres in forum New To Java
    Replies: 5
    Last Post: 12-12-2011, 11:37 PM
  2. Need some understanding and help!
    By Kevinius in forum New To Java
    Replies: 8
    Last Post: 05-14-2011, 05:50 AM
  3. Subclass understanding?
    By LifeElixer in forum New To Java
    Replies: 6
    Last Post: 04-13-2011, 08:57 AM
  4. need help in understanding collection
    By ShinTec in forum Advanced Java
    Replies: 2
    Last Post: 04-24-2010, 02:49 AM
  5. Help on understanding a program
    By newbie225 in forum New To Java
    Replies: 1
    Last Post: 11-10-2009, 12:53 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •