Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

errors running .java program using jGrasp

807600Oct 25 2007 — edited Oct 26 2007
If anybody could help, it would be greatly appreciated!

I am trying to execute a .java program using jGrasp but get the following errors:

----jGRASP exec: java MaintainQueue

java.lang.NoSuchMethodError: main
Exception in thread "main"
----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.

It compiles fine but I do not understand why it doesn't run. Below is the code for the .java file (maybe overkill posting the entire code but I don't want to leave anything out):

import javax.swing.*;
import java.util.*;

/** Class to maintain a queue of customers.
* @author Koffman & Wolfgang
* */

public class MaintainQueue {

// Data Field
private Queue < String > customers;

// Constructor
/** Create an empty queue. */
public MaintainQueue() {
customers = new LinkedList < String > ();
}

/** Performs the operations selected on queue customers.
pre: customers has been created.
post: customers is modified based on user selections.
*/
public void processCustomers() {
int choiceNum = 0;
String[] choices = {
"add", "peek", "remove", "size", "position", "quit"};

// Perform all operations selected by user.
while (choiceNum < choices.length - 1) {
// Select the next operation.
choiceNum = JOptionPane.showOptionDialog(null,
"Select an operation on customer queue",
"Queue menu",
JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.QUESTION_MESSAGE, null,
choices, choices[0]);

// Process the current choice.
try {
String name;
switch (choiceNum) {
case 0:
name = JOptionPane.showInputDialog
("Enter new customer name");
customers.offer(name);
JOptionPane.showMessageDialog(null,
"Customer " + name
+ " added to the queue");
break;
case 1:
JOptionPane.showMessageDialog(null,
"Customer " + customers.element()
+ " is next in the queue");
break;
case 2:
JOptionPane.showMessageDialog(null,
"Customer " + customers.remove()
+ " removed from the queue");
break;
case 3:
JOptionPane.showMessageDialog(null,
"Size of queue is " + customers.size());
break;
case 4:
name = JOptionPane.showInputDialog
("Enter customer name");
int countAhead = 0;
for (String nextName : customers) {
if (!nextName.equals(name)) {
countAhead++;
}
else {
JOptionPane.showMessageDialog(null,
"The number of customers ahead of "
+ name + " is " + countAhead);
break; // Customer found, exit loop.
}
}

// Check whether customer was found.
if (countAhead == customers.size())
JOptionPane.showMessageDialog(null,
name + " is not in queue");
break;
case 5:
JOptionPane.showMessageDialog(null,
"Leaving customer queue. "
+
"\nNumber of customers in queue is "
+ customers.size());
break;
default:
JOptionPane.showMessageDialog(null,
"Invalid selection");
break;
}
}
catch (NoSuchElementException e) {
JOptionPane.showMessageDialog(null,
"The Queue is empty", "",
JOptionPane.ERROR_MESSAGE);
}
}
}
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 23 2007
Added on Oct 25 2007
1 comment
413 views