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 2 of 2

Thread: More error .

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

    Default More error .

    Imma new java user.
    I tried this code to run but, it didn't
    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();
    }
    }
    thanks in advance


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,612
    My Mood
    Hungover
    Thanks
    145
    Thanked 658 Times in 563 Posts

    Default Re: More error .

    Sorry, but that's not how this works. For starters, you don't even tell us what the actual problem or Exception is. You don't use code tags, and you didn't use a meaningful post title.

    Saying "it didn't" is as useful for us as us saying "then make it do" is useful for you.

    Edit- Also, how did you try to run it? Be precise.
    Last edited by KevinWorkman; January 26th, 2011 at 02:14 PM.
    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!