Page 1 of 2 12 LastLast
Results 1 to 20 of 24

Thread: small error

  1. #1
    ayoood is offline Member
    Join Date
    May 2008
    Posts
    39
    Rep Power
    0

    Default small error

    i wrote this code when i compile it i get this error so what is the solution??

    java.lang.NoSuchMethodError: main
    Exception in thread "main"
    Process completed.

    class MyQueue
    {
    private int[] arr;
    private int head;
    private int tail;
    private int size;
    private int count;
    public MyQueue(int size)
    {
    arr = new int[size];
    head = 0;
    tail = 0;
    count = 0;
    this.size = size;
    }
    public void Enqueue(int value)
    {
    if(!IsFull())
    {
    arr[tail] = value;
    tail = (tail + 1) % size;
    count++;
    }
    }
    public int Dequeue()
    {
    if (!IsEmpty())
    {
    int result = arr[head];
    head = (head + 1) % size;
    count--;
    return result;
    }
    return 0;
    }
    public Boolean IsFull()
    {
    return count == size;
    }
    public Boolean IsEmpty()
    {
    return count == 0;
    }
    }
    Last edited by ayoood; 05-26-2008 at 12:53 PM.

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Strange seems to me your code is fine. Lets add generics there.

    Java Code:
    private LinkedList<Object> list = new LinkedList<Object>();

  3. #3
    ayoood is offline Member
    Join Date
    May 2008
    Posts
    39
    Rep Power
    0

    Default

    sorry i put the wrong programme this is my our programme and i get this error
    Last edited by ayoood; 05-26-2008 at 12:55 PM.

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Java Code:
    public class StackL {
    
        private LinkedList<Object> list = new LinkedList<Object>();
    
        public void push(Object v) {
            list.addFirst(v);
        }
    
        public Object top() {
            return list.getFirst();
        }
    
        public Object pop() {
            return list.removeFirst();
        }
    
        public static void main(String[] args) {
            StackL stack = new StackL();
            for (int i = 0; i < 10; i++)
                stack.push(new Integer(i));
            
            System.out.println(stack.top());
            System.out.println(stack.top());
            System.out.println(stack.pop());
            System.out.println(stack.pop());
            System.out.println(stack.pop());
        }
    }

  5. #5
    ayoood is offline Member
    Join Date
    May 2008
    Posts
    39
    Rep Power
    0

    Default

    this programme work with me i put the wrong programme now i upload the right programme so could you fig what the solution for this programme

  6. #6
    ayoood is offline Member
    Join Date
    May 2008
    Posts
    39
    Rep Power
    0

    Default

    there is no body can fig what should i do my our code correct but iwhen i compile it i get that error
    java.lang.NoSuchMethodError: main
    Exception in thread "main"
    Process completed.

  7. #7
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    It's not a compilation error. It's a run time error. In your class there is no main method. So you can't runt it. Only thing you can do is compiling it.

  8. #8
    ayoood is offline Member
    Join Date
    May 2008
    Posts
    39
    Rep Power
    0

    Default

    so what should i do to run it what method should i write it to rin the programme??

  9. #9
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  10. #10
    ayoood is offline Member
    Join Date
    May 2008
    Posts
    39
    Rep Power
    0

    Default

    sorry about that in me programme i should write public statice void main(String args[]); that you main ??????

  11. #11
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  12. #12
    ayoood is offline Member
    Join Date
    May 2008
    Posts
    39
    Rep Power
    0

    Default

    could you plz tell me in which line i put it

    thank you for reply

  13. #13
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    I don't know what is your requirement there. But the basis thing you have to do is this.

    Java Code:
    class MyQueue {
        private int[] arr;
        private int head;
        private int tail;
        private int size;
        private int count;
    
        public MyQueue(int size) {
            arr = new int[size];
            head = 0;
            tail = 0;
            count = 0;
            this.size = size;
        }
    
        public void Enqueue(int value) {
            if(!IsFull()) {
                arr[tail] = value;
                tail = (tail + 1) % size;
                count++;
            }
        }
    
        public int Dequeue() {
            if (!IsEmpty()) {
                int result = arr[head];
                head = (head + 1) % size;
                count--;
                return result;
            }
            return 0;
        }
    
        public Boolean IsFull() {
            return count == size;
        }
    
        public Boolean IsEmpty() {
            return count == 0;
        }
        
        public static void main(String[] args) {
            MyQueue mq = new MyQueue(10);
            
            mq.Enqueue(3);
            mq.Dequeue();
        }
    }

  14. #14
    ayoood is offline Member
    Join Date
    May 2008
    Posts
    39
    Rep Power
    0

    Default

    thank you for your help

  15. #15
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  16. #16
    ayoood is offline Member
    Join Date
    May 2008
    Posts
    39
    Rep Power
    0

    Default

    now it’s run with me but i didn’t get any value for output only process complete

  17. #17
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Because you don't have print any value to the console. What you want to get as output in your application?

  18. #18
    ayoood is offline Member
    Join Date
    May 2008
    Posts
    39
    Rep Power
    0

    Default

    i would like to get 3

  19. #19
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    What you mean 3. You want to print value 3. There is no meaning. To just print a number, what you have done here. From where you found this code.

  20. #20
    ayoood is offline Member
    Join Date
    May 2008
    Posts
    39
    Rep Power
    0

Page 1 of 2 12 LastLast

Similar Threads

  1. small issues with a program
    By jimJohnson in forum New To Java
    Replies: 6
    Last Post: 04-25-2008, 09:28 AM
  2. Building small web application in java for practice.
    By Saurabh321 in forum New To Java
    Replies: 1
    Last Post: 02-01-2008, 04:38 PM
  3. Small scale Java Editor
    By Greenfrog99 in forum AWT / Swing
    Replies: 0
    Last Post: 01-27-2008, 09:46 PM
  4. Replies: 1
    Last Post: 01-05-2008, 08:48 PM
  5. Small tennis simulation in Java
    By diego in forum New To Java
    Replies: 1
    Last Post: 12-02-2007, 02:32 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
  •