|
|
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.
|
|

05-26-2008, 01:44 PM
|
|
Member
|
|
Join Date: May 2008
Posts: 39
|
|
|
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.
|
|

05-26-2008, 01:49 PM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,609
|
|
Strange seems to me your code is fine. Lets add generics there.
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.
|
|

05-26-2008, 01:52 PM
|
|
Member
|
|
Join Date: May 2008
Posts: 39
|
|
|
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.
|
|

05-26-2008, 01:55 PM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,609
|
|
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.
|
|

05-26-2008, 03:09 PM
|
|
Member
|
|
Join Date: May 2008
Posts: 39
|
|
|
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
|
|

05-26-2008, 11:07 PM
|
|
Member
|
|
Join Date: May 2008
Posts: 39
|
|
|
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.
|
|

05-27-2008, 05:44 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,609
|
|
|
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.
|
|

05-27-2008, 10:30 AM
|
|
Member
|
|
Join Date: May 2008
Posts: 39
|
|
|
so what should i do to run it what method should i write it to rin the programme??
|
|

05-27-2008, 10:32 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,609
|
|
|
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.
|
|

05-27-2008, 12:07 PM
|
|
Member
|
|
Join Date: May 2008
Posts: 39
|
|
|
sorry about that in me programme i should write public statice void main(String args[]); that you main ??????
|
|

05-27-2008, 12:14 PM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,609
|
|
|
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.
|
|

05-27-2008, 12:25 PM
|
|
Member
|
|
Join Date: May 2008
Posts: 39
|
|
|
could you plz tell me in which line i put it
thank you for reply
|
|

05-27-2008, 12:30 PM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,609
|
|
I don't know what is your requirement there. But the basis thing you have to do is this.
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.
|
|

05-27-2008, 12:32 PM
|
|
Member
|
|
Join Date: May 2008
Posts: 39
|
|
|
thank you for your help
|
|

05-27-2008, 12:37 PM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,609
|
|
|
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.
|
|

05-27-2008, 01:02 PM
|
|
Member
|
|
Join Date: May 2008
Posts: 39
|
|
|
now it’s run with me but i didn’t get any value for output only process complete
|
|

05-27-2008, 01:07 PM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,609
|
|
|
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.
|
|

05-27-2008, 01:28 PM
|
|
Member
|
|
Join Date: May 2008
Posts: 39
|
|
|
i would like to get 3
|
|

05-27-2008, 01:31 PM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,609
|
|
|
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.
|
|

05-27-2008, 01:46 PM
|
|
Member
|
|
Join Date: May 2008
Posts: 39
|
|
|
i get it from one sit but i don’t remember which sit
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
| |