• Post Reply Bookmark Topic Watch Topic
  • New Topic

error: class, interface or enum expected  RSS feed

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am building a java program for a uni project and am using J creator. I have the folowing code and when i build it i get the error:class,interface,or enum expected. The error is in the bolded part im just stuck as to what it is
.
import javax.swing.JOptionPane;
class LondonWalks
{
public static void main(String[]args)
{

int count = 0;
String startpoint[] = new String[50];
String walkdesc[] = new String[50];
int length[] = new int[50];


int ABC=0;
while (ABC!= 4)
{

String a = JOptionPane.showInputDialog(null, "Please select 1,2,3 or 4 from the menu below" + "\n" +
"1) - New Record" + "\n" +
"2) - Search" + "\n" +
"3) - Print Data" + "\n" +
"4) - Exit");
ABC = Integer.parseInt(a);

if (ABC==1)
{
addrecord(startpoint ,walkdesc ,length ,count);
// it calls the method(it runs the method)
count++;
//it increments the count variable by 1

}
if(ABC==2){
printrecord(args);

}
}
}
public static void addrecord(String[] startpoint, String[] walkdesc, int[] length, int count)
{

startpoint[count] = JOptionPane.showInputDialog("Start Point");
walkdesc[count] = JOptionPane.showInputDialog("Description");
length[count] = Integer.parseInt(JOptionPane.showInputDialog("Length"));

}

}
public static void printrecord(String[] startpoint, String[] walkdesc, int[] length, int count)
{

for(int i=0; i<startpoint.length; i++){
System.out.println(startpoint [i]+walkdesc[i]+length[i]);
}

}
 
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please EaseUp. Nobody here cares that you are under a time crunch. Mostly what that does is make people not want to help you.

Also, it would help if you learned to UseCodeTags. It's much easier to read it if you do, as you can see below. Of course, you can't use bold tags inside it, but if you would post the full and complete error message, it tells us exactly what line the problem is on.

 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now that I can read your java, the problem is simple to fix.

All methods must be inside the class. Your addrecord and printrecord are both outside the closing brace of your class (the one on line 37). Move them inside, save, and recompile.
 
Marshal
Posts: 56610
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have other design problems. Marking all members static is usually a design error.
 
Campbell Ritchie
Marshal
Posts: 56610
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can I point you to some suggestions about formatting. If you format your code correctly, you can see errors like what you were suffering much more easily.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!