Reputation: 13
So I am making a simple menu with Option dialog, but it just does not compile, not sure why.
This is the error:
Inventory.java:21: error: illegal start of expression
public static String promptInventory(String MName, String[] options)
Not sure what to do here. Also the way I have it set up, it should cycle back to the menu each time right? But I don't think it serves my purposes...
import java.util.ArrayList;
import javax.swing.JOptionPane;
import javax.swing.JTextArea;
import javax.swing.JScrollPane;
class Inventory
{
public static void main(String arg[])
{
Database db = new Database();
Database dpl = new Database();
final String[] MENU_OPTIONS = {"exit", "Add product", "Sell product", "Delete product", "Modify product",
"Display information"};
final String MENU_NAME = "Inventory";
String selection = promptInventory(MENU_NAME, MENU_OPTIONS);
public static String promptInventory(String MName, String[] options)
{
int selection = JOptionPane.showOptionDialog(null,
"Enter your Transaction Type",
MName,
JOptionPane.DEFAULT_OPTION,
JOptionPane.QUESTION_MESSAGE,
null, options, options[0] );
return (String)options[selection];
}
//logic
switch ( selection )
{
case "exit" :
break;
case "Add product" :
break;
case "Sell product" :
break;
}
String selection = promptInventory(MENU_NAME, MENU_OPTIONS);
}
}
Upvotes: 0
Views: 54
Reputation: 14705
Use a tool that can format/indent the code for you. That makes these kind of errors obvious.
Your promptInventory
method is now inside the main method and that is illegal.
Your class with methods should be indented like
class Inventory
{
public void method(){
} // end of method
public void nextMethod(){
// No methods in here.
}
}// end class
Upvotes: 1