Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-26-2008, 01:44 PM
Member
 
Join Date: May 2008
Posts: 39
ayoood is on a distinguished road
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 01:53 PM.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-26-2008, 01:49 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,609
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Strange seems to me your code is fine. Lets add generics there.

Code:
private LinkedList<Object> list = new LinkedList<Object>();
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 05-26-2008, 01:52 PM
Member
 
Join Date: May 2008
Posts: 39
ayoood is on a distinguished road
sorry i put the wrong programme this is my our programme and i get this error

Last edited by ayoood : 05-26-2008 at 01:55 PM.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 05-26-2008, 01:55 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,609
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
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()); } }
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 05-26-2008, 03:09 PM
Member
 
Join Date: May 2008
Posts: 39
ayoood is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 05-26-2008, 11:07 PM
Member
 
Join Date: May 2008
Posts: 39
ayoood is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 05-27-2008, 05:44 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,609
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
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.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 05-27-2008, 10:30 AM
Member
 
Join Date: May 2008
Posts: 39
ayoood is on a distinguished road
so what should i do to run it what method should i write it to rin the programme??
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 05-27-2008, 10:32 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,609
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Write the main method.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #10 (permalink)  
Old 05-27-2008, 12:07 PM
Member
 
Join Date: May 2008
Posts: 39
ayoood is on a distinguished road
sorry about that in me programme i should write public statice void main(String args[]); that you main ??????
Bookmark Post in Technorati
Reply With Quote
  #11 (permalink)  
Old 05-27-2008, 12:14 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,609
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Yes it is. On that methods call the starting point on your written code.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #12 (permalink)  
Old 05-27-2008, 12:25 PM
Member
 
Join Date: May 2008
Posts: 39
ayoood is on a distinguished road
could you plz tell me in which line i put it

thank you for reply
Bookmark Post in Technorati
Reply With Quote
  #13 (permalink)  
Old 05-27-2008, 12:30 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,609
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
I don't know what is your requirement there. But the basis thing you have to do is this.

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(); } }
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #14 (permalink)  
Old 05-27-2008, 12:32 PM
Member
 
Join Date: May 2008
Posts: 39
ayoood is on a distinguished road
thank you for your help
Bookmark Post in Technorati
Reply With Quote
  #15 (permalink)  
Old 05-27-2008, 12:37 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,609
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Is that what you looking?
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #16 (permalink)  
Old 05-27-2008, 01:02 PM
Member
 
Join Date: May 2008
Posts: 39
ayoood is on a distinguished road
now it’s run with me but i didn’t get any value for output only process complete
Bookmark Post in Technorati
Reply With Quote
  #17 (permalink)  
Old 05-27-2008, 01:07 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,609
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Because you don't have print any value to the console. What you want to get as output in your application?
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #18 (permalink)  
Old 05-27-2008, 01:28 PM
Member
 
Join Date: May 2008
Posts: 39
ayoood is on a distinguished road
i would like to get 3
Bookmark Post in Technorati
Reply With Quote
  #19 (permalink)  
Old 05-27-2008, 01:31 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,609
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
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.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #20 (permalink)  
Old 05-27-2008, 01:46 PM
Member
 
Join Date: May 2008
Posts: 39
ayoood is on a distinguished road
i get it from one sit but i don’t remember which sit
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
small issues with a program jimJohnson New To Java 6 04-25-2008 10:28 AM
Building small web application in java for practice. Saurabh321 New To Java 1 02-01-2008 05:38 PM
Small scale Java Editor