954,545 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

JAVA Illegal Start of Expression Error

Could someone please help me out. I have an illegal start of an expression error at line 8 in the following code.

package untitled5;

public class Untitled1 {
  public static void main(String[] args) {

    

      public static void main(String[] args) {
        int start_system, add_modify, add_modify_animal_data, report,
            exit_system;
        int check = menu();
        while (check != 4) {
          if (check == 1) {
            add_modify_data();
          }
          else
          if (check == 2) {
            add_modify_medical_data();
          }
          else
          if (check == 3) {
            report();
          }
          check = menu();
        }

        exit_system();
        System.exit(0);
      }

      {
        public static void start_system() {
          System.out.println("Start_system now");
        }
      }
//sets up the output
        public static int menu() {
          int check;
          String output = "Modify Animal Data" + "\n " +
              "1. Add/Modify Animal Data " + "\n" +
              "2. Add/modify Meical Data " + "\n" +
              "3. Report Section " + "\n" +
              "4. Exit " + "\n " + "\n " + " Enter Your Selection:";
          String scheck = JOptionPane.showInputDialog(null, output, " ",
              JOptionPane.QUESTION_MESSAGE);
          check = Integer.parseInt(scheck);
          return check;
        }
        public static void add_modify() {
          int check1;
          while (check1 != 4) {
            if (check1 == 1) {
              add_animal_data();
            }
            else
            if (check1 == 2) {
              delete_animal_data();
            }
            else
            if (check1 == 3) {
              change_animal_data();

            }
            check1 = menu();

          }
          exit_system();
          System.exit(0);
          String output = "Modify Animal Data " + "\n " +
              "1. Add Animal Data " + "\n" +
              "2. Modify Animal Data " + "\n" +
              "3. Change Animal Data " + "\n" +
              "4. Exit " + "\n " + "\n " + " Enter Your Selection:";
          String scheck = JOptionPane.showInputDialog(null, output, " ",
              JOptionPane.QUESTION_MESSAGE);
          check1 = Integer.parseInt(scheck);
        }
        public static void add_modify_medical_data() {
          int check2;
          while (check2 != 4) {
            if (check2 == 1) {
              add_medical();

            }
            else
            if (check2 == 2) {
              delete_medical();

            }
            else
            if (check2 == 3) {
              change_medical();

            }
            check2 = menu();

          }
          exit_system();
          System.exit(0);
          String output = "Modify Medical Data " + "\n " +
              "1. Add Medical Data " + "\n" +
              "2. Modify Medical Data " + "\n" +
              "3. Change Change Data " + "\n" +
              "4. Exit " + "\n " + "\n " + " Enter Your Selection:";
          String scheck = JOptionPane.showInputDialog(null, output, " ",
              JOptionPane.QUESTION_MESSAGE);
          check2 = Integer.parseInt(scheck);
        }
        public static void report() {
          System.out.println("in Report");
        }
        public static void exit_system() {
          System.out.println("in exit system");
        };
  
    }
  }


Thank you

lrw0831
Newbie Poster
2 posts since Mar 2006
Reputation Points: 10
Solved Threads: 0
 

of course you do. :)

You're trying to declare a method inside of a method.

Remove the first public static void main method and then a ending } near the bottom of your code and that should help you out some.

Also, you have an extra ; at the end of your exit_system method.

hooknc
Posting Whiz in Training
219 posts since Aug 2005
Reputation Points: 11
Solved Threads: 8
 

I am getting the same error message except now it is at line 29

lrw0831
Newbie Poster
2 posts since Mar 2006
Reputation Points: 10
Solved Threads: 0
 

of course you are. :)

You really need to check your combination of open and close brackets. You must have an equal amout of both and you must fallow the java rules for declaration of attributes and methods.

I would recommend picking up a basic java book to learn these rules.

[offtopic]
Arn't the smiles here about the most evil things you've ever seen? The normal smile looks like he just took you for all you're worth.
[/offtopic]

hooknc
Posting Whiz in Training
219 posts since Aug 2005
Reputation Points: 11
Solved Threads: 8
 

of course you are. :)

You really need to check your combination of open and close brackets. You must have an equal amout of both and you must fallow the java rules for declaration of attributes and methods.

I would recommend picking up a basic java book to learn these rules.

[offtopic] Arn't the smiles here about the most evil things you've ever seen? The normal smile looks like he just took you for all you're worth. [/offtopic]

True it's more like a condescending smirk, I don't care tho... I like to antognise people...it's fun either way. :)

iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 

hi can anyone help me please. I'm having problem with my program. It's only one error illegal starts of expression in public void check (), at line 53. What it is mean?..

import javax.swing.JOptionPane;
//public class waiter{
//public static void main(String [] args)
class waiter
 
 
{
private double tab;
public waiter(String name);
{
System.out.println("My name is "+ name +", and i'll be your waiter!");
tab = 0.0;
}
public double priceof(String s);
{
double price;
if (s.equals("Chicken"))
{price = 5.95;}
else
{//burger fries
if (s.equals("burger"))
{price = 4.95; }
else
{price = 1.95;}
 
}//burger or fries
return price;
}//priceof
public void order(String s)
{
if(s.equals("Chicken"))
{
tab = tab + 5.95;
}// burger fries
else 
{//burger fries
if (s.equals("Burger"))
{
tab = tab + 4.95;
}
else
{ 
tab = tab + 1.95;
}
}//price of
 
public void check()
{
System.out.println("Please pay $" + tab+",null");
}
 
}//end of class waiter
public class objects3
{
public static void main(String [] args)
{
waiter ourwaiter;
ourwaiter = new waiter ("Manfred");// makes a waiter object
double x; //to hold price of burger
double y; //varikable to hold price of chicken
x = ourwaiter.priceof("burger");
y = ourwaiter.priceof("chicken");
if (x<y)// buy cheaper product
{
System.out.println("I'll take the burger because it's cheaper");
ourwaiter.order("Burger");
}//burger
else
{
System.out.println("I'll take the chicken. ");
ourwaiter.order("chicken");
}//chicekn
System.out.println("And i'll have fries with that");
ourwaiter.oreder("Fries");
System.out.println("\n eat eat....\n");
 
ourwaiter.check();
}//main
}//class objects3
j3p0yz
Newbie Poster
9 posts since Jun 2007
Reputation Points: 10
Solved Threads: 0
 

use code tags if you want people to read your code.
And don't go hijacking other peoples' threads, not even old ones like this.

jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 

i'm sory i don't know where to type my program. i'm very sory..

j3p0yz
Newbie Poster
9 posts since Jun 2007
Reputation Points: 10
Solved Threads: 0
 

h..i can anyone help me please. I'm having problem with this program. It's only one error illegal starts of expression in public void check (), at line 53. What it is mean?..

import javax.swing.JOptionPane;

class waiter


{
private double tab;
public waiter(String name);
{
System.out.println("My name is "+ name +", and i'll be your waiter!");
tab = 0.0;
}
public double priceof(String s);
{
double price;
if (s.equals("Chicken"))
{price = 5.95;}
else
{//burger fries
if (s.equals("burger"))
{price = 4.95; }
else
{price = 1.95;}

}//burger or fries
return price;
}//priceof
public void order(String s)
{
if(s.equals("Chicken"))
{
tab = tab + 5.95;
}// burger fries
else 
{//burger fries
if (s.equals("Burger"))
{
tab = tab + 4.95;
}
else
{ 
tab = tab + 1.95;
}
}//price of

public void check()
{
System.out.println("Please pay $" + tab+",null");
}

}
public class objects3
{
public static void main(String [] args)
{
waiter ourwaiter;
ourwaiter = new waiter ("Manfred");// makes a waiter object
double x; 
double y; 
x = ourwaiter.priceof("burger");
y = ourwaiter.priceof("chicken");
if (x<y)// buy cheaper product
{
System.out.println("I'll take the burger because it's cheaper");
ourwaiter.order("Burger");
}
else
{
System.out.println("I'll take the chicken. ");
ourwaiter.order("chicken");
}
System.out.println("And i'll have fries with that");
ourwaiter.oreder("Fries");
System.out.println("\n eat eat....\n");

ourwaiter.check();
}
}
j3p0yz
Newbie Poster
9 posts since Jun 2007
Reputation Points: 10
Solved Threads: 0
 

As Jwenting mentioned, you need to start a new thread with your question and place your code between code tags to make it more readable. See the post at the top of the forum about code tags.

An illegal start of expression means that you have misformatted your code and it cannot be parsed correctly. This would include things like missing braces or parens, declaring a method within a method, missing semi-colon, etc.

Ezzaral
Posting Genius
Moderator
15,986 posts since May 2007
Reputation Points: 3,250
Solved Threads: 847
 

Please read the following about code tags

http://www.daniweb.com/forums/announcement8-3.html

iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 

Hey, this thread actually HELPED me...I'm a newbie to Java. I didn't realize I was trying to declare a method from within another method. Java can be difficult to debug sometimes although the NetBeans IDE is VERY helpful.

stoven
Newbie Poster
1 post since Jan 2010
Reputation Points: 10
Solved Threads: 0
 

I am trying to write a program that reads three integers and prints their average. This is what I got so far, but every time I go to compile this program so that I can run it I keep receiving one error message in reference to the "system.out..." statement saying that it is an illegal start of expression. This maybe something simple that I turned into difficult. Am I going about this the right way? Please help.

public class IntApp
{
    public static void main (String[] args)
    {

        final int BASE = 3;

       AVER = (x + y + z) / BASE;

       int x = 95;
       int y = 85;
       int z = 99;

        System.out.println ("The average of int  xyz: " + AVER +);

    }
}
miidas
Newbie Poster
1 post since Mar 2010
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You