Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 9 of 9

Thread: java.lang.NoClassDefFoundError

  1. #1
    Junior Member
    Join Date
    Jan 2011
    Posts
    5
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default java.lang.NoClassDefFoundError

    Imma new java user
    i don't know what's the problem on my code

    public class Main {
    	public void queueExample() {
     
    		Queue queue = new LinkedList();
     
    		queue.add("item1");
    		queue.add("item2");
    		queue.offer("item3");
    		queue.offer("item4");
     
    		System.out.println("remove: " + queue.remove());
    		System.out.println("element: " + queue.element());
    		System.out.println("poll: " + queue.poll());
    		System.out.println("peek: " + queue.peek());
    	}
     
    	public static void main (String [] args) {
    		new Main() queueExample();
    	}
    }

    and the output of this code is

    java.lang.NoClassDefFoundError: Main
    Exception in thread "main"
    Process completed.

  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: java.lang.NoClassDefFoundError

    I'm pretty sure you're just missing a period between Main() and queueExample(). Although I don't see how that would result in the Exception you're talking about.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. The Following User Says Thank You to KevinWorkman For This Useful Post:

    anonymous001 (January 26th, 2011)

  4. #3
    Junior Member
    Join Date
    Jan 2011
    Posts
    5
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: java.lang.NoClassDefFoundError


  5. #4
    Forum Squatter newbie's Avatar
    Join Date
    Nov 2010
    Location
    North Wales
    Posts
    661
    My Mood
    Stressed
    Thanks
    28
    Thanked 115 Times in 106 Posts
    Blog Entries
    1

    Default Re: java.lang.NoClassDefFoundError

    -Edit...Removed Post.
    anonymous001 corrected convention issue and started new Thread..which made my post void
    Last edited by newbie; January 26th, 2011 at 02:11 PM.
    Please use [highlight=Java]//code goes here...[/highlight] tags when posting your code

  6. The Following User Says Thank You to newbie For This Useful Post:

    anonymous001 (January 26th, 2011)

  7. #5
    Junior Member
    Join Date
    Jan 2011
    Posts
    5
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: java.lang.NoClassDefFoundError

    Quote Originally Posted by newbie View Post
    -Edit...Removed Post.
    anonymous001 corrected convention issue and started new Thread..which made my post void

     import java.util.LinkedList;
    import java.util.Queue;
     
    /**
    *
    * @author javadb.com
    */
    public class Main {
     
    /**
    * Example method for using a Queue
    */
    public void queueExample() {
     
    Queue queue = new LinkedList();
     
    //Using the add method to add items.
    //Should anything go wrong an exception will be thrown.
    queue.add("item1");
    queue.add("item2");
     
    //Using the offer method to add items.
    //Should anything go wrong it will just return false
    queue.offer("Item3");
    queue.offer("Item4");
     
    //Removing the first item from the queue.
    //If the queue is empty a java.util.NoSuchElementException will be thrown. 
    System.out.println("remove: " + queue.remove());
     
    //Checking what item is first in line without removing it
    //If the queue is empty a java.util.NoSuchElementException will be thrown. 
    System.out.println("element: " + queue.element());
     
    //Removing the first item from the queue.
    //If the queue is empty the method just returns false. 
    System.out.println("poll: " + queue.poll());
     
    //Checking what item is first in line without removing it
    //If the queue is empty a null value will be returned. 
    System.out.println("peek: " + queue.peek());
     
    }
     
     
    /**
    * @param args the command line arguments
    */
    public static void main(String[] args) {
    new Main().queueExample();
    }
    }

    i tried this code but it didn't run.

  8. #6
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: java.lang.NoClassDefFoundError

    For the sake of everyone's sanity, I urge you to keep each problem in its own Thread. Please keep the issue with running your code in the Thread you started for it: http://www.javaprogrammingforums.com...ore-error.html

    Full disclosure- I'm not a mod. Do what you want, but keep in mind that you should probably be making it easier for people to help you, not harder.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  9. #7
    Junior Member
    Join Date
    Jan 2011
    Posts
    5
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: java.lang.NoClassDefFoundError

    Quote Originally Posted by KevinWorkman View Post
    For the sake of everyone's sanity, I urge you to keep each problem in its own Thread. Please keep the issue with running your code in the Thread you started for it: http://www.javaprogrammingforums.com...ore-error.html

    Full disclosure- I'm not a mod. Do what you want, but keep in mind that you should probably be making it easier for people to help you, not harder.
    Sorry kev i accidentally clicked the submit :[
    okay. sorry sorry

  10. #8
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: java.lang.NoClassDefFoundError

    i tried this code but it didn't run
    This is quite uninformative as to the problem...does it compile? Are there exceptions?

  11. #9
    Member DavidFongs's Avatar
    Join Date
    Oct 2010
    Location
    Minneapolis, MN
    Posts
    107
    Thanks
    1
    Thanked 45 Times in 41 Posts

    Default Re: java.lang.NoClassDefFoundError

    Ran unchanged for me. Please post how you are attempting to run your code, and any errors.

Similar Threads

  1. Replies: 13
    Last Post: October 13th, 2010, 11:20 AM
  2. Replies: 3
    Last Post: May 15th, 2010, 02:05 PM
  3. AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space
    By nasi in forum What's Wrong With My Code?
    Replies: 6
    Last Post: March 25th, 2010, 10:37 PM
  4. Replies: 2
    Last Post: November 3rd, 2009, 06:28 AM
  5. Replies: 1
    Last Post: October 25th, 2009, 11:54 AM