Results 1 to 20 of 20
  1. #1
    thyks is offline Member
    Join Date
    Jun 2012
    Posts
    19
    Rep Power
    0

    Question Problem witch "Illegal start of expression"

    Hello all, i have a problem witch my app (not first app).
    Code of the program:
    Java Code:
    import java.util.Scannner;
    public class Michs {
    	public static void main(String [] args) {
    	int c = 0;
    	Scanner scan = new Scanner (System.in);
    	System.out.printIn("XXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
    	System.out.printIn("X Witaj w programie Michs!  X");
    	System.out.printIn("XXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
    	System.out.printIn("X       JavaWER wer 0.1     X");
    	System.out.printIn("XXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
    	System.out.printIn("[1] Rozpocznij quiz");
    	System.out.printIn("[2] Wyjdz z programu");
    	String in;
    	in = scan.nextLine();
    	if(in.equals("1"))
    	{
    		int lidzba = 2;
    		System.out.printIn("Ile to jest 1+1?");
    		String in;
    		if(in.equals("2"));
    		{
    		System.out.printIn("Dobrze!");
    		}
            if (else);    <--------------- Heres the problem.  :(-:
            {
    		System.out.printIn("Zle! 1+1 to jest 2.");
    		}
    	}
    	}
    }
    i have my own compilator in batch:
    @echo off
    title kompilator
    set path=%path%;C:\Program Files\Java\jdk1.7.0\bin
    echo zalecana wersja jdk: 1.7.0
    echo umiesc ten program w folderze z plikiem .java!!!
    set /p war=co chesz skompilowac?
    javac %war%.java
    echo gotowe!
    pause
    exit
    Last edited by Fubarable; 06-10-2012 at 08:35 PM. Reason: code tags added

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Problem witch "Illegal start of expression"

    Moderator edit: [code] [/code] tags added to your post.

    Now as to your problem,

    Java Code:
    if (else)
    doesn't make much sense. else is a key word and can't or shouldn't be used inside of an if boolean block. Perhaps you mean to just use else alone.

    Also, you'll want to not end the line with a semi-colon. Please have a look at how the tutorials suggest you do if blocks: if-then-else statements

  3. #3
    thyks is offline Member
    Join Date
    Jun 2012
    Posts
    19
    Rep Power
    0

    Default Re: Problem witch "Illegal start of expression"

    Quote Originally Posted by Fubarable View Post
    Moderator edit: [code] [/code] tags added to your post.

    Now as to your problem,

    Java Code:
    if (else)
    doesn't make much sense. else is a key word and can't or shouldn't be used inside of an if boolean block. Perhaps you mean to just use else alone.

    Also, you'll want to not end the line with a semi-colon. Please have a look at how the tutorials suggest you do if blocks: if-then-else statements
    Thanks you for help :)

    But when i changed the code to this
    Java Code:
    import java.util.Scannner;
    public class Michs {
    	public static void main(String [] args) {
    	int c = 0;
    	Scanner scan = new Scanner (System.in);
    	System.out.printIn("XXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
    	System.out.printIn("X Witaj w programie Michs!  X");
    	System.out.printIn("XXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
    	System.out.printIn("X       JavaWER wer 0.1     X");
    	System.out.printIn("XXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
    	System.out.printIn("[1] Rozpocznij quiz");
    	System.out.printIn("[2] Wyjdz z programu");
    	String in;
    	in = scan.nextLine();
    	if(in.equals("1"))
    	{
    		int lidzba = 2;
    		System.out.printIn("Ile to jest 1+1?");
    		String in;
    		if(in.equals("2"));
    		{
    		System.out.printIn("Dobrze!");
            } else {
    		System.out.printIn("Zle! 1+1 to jest 2.");
    		}
    	}
    	}
    }
    this maked a new problem:
    else without if.
    When im adding 'if', this generates next error: add ( and ) characters and illegal start expression... [Moderator edit: obscenity removed]...
    Sorry for my terrible english.
    PS
    My JDK version: 1.7.0
    My java version:6 update 31
    Last edited by DarrylBurke; 06-10-2012 at 09:18 PM. Reason: Removed obscene word

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: Problem witch "Illegal start of expression"

    Please mind your language.

    Fubarable already told you not to end if (...) statement lines with a semicolon. He also gave you a link to a tutorial which has easy to follow example code.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    thyks is offline Member
    Join Date
    Jun 2012
    Posts
    19
    Rep Power
    0

    Angry Re: Problem witch "Illegal start of expression"

    Quote Originally Posted by DarrylBurke View Post
    Please mind your language.

    Fubarable already told you not to end if (...) statement lines with a semicolon. He also gave you a link to a tutorial which has easy to follow example code.

    db
    I still have the problem... nothing changed...
    Please look at code from The if-then and if-then-else Statements (The Java™ Tutorials > Learning the Java Language > Language Basics) : (look at line 15)
    Java Code:
    class IfElseDemo {
        public static void main(String[] args) {
    
            int testscore = 76;
            char grade;
    
            if (testscore >= 90) {
                grade = 'A';
            } else if (testscore >= 80) {
                grade = 'B';
            } else if (testscore >= 70) {
                grade = 'C';
            } else if (testscore >= 60) {
                grade = 'D';
        >>>    } else { <<<
                grade = 'F';
            }
            System.out.println("Grade = " + grade);
        }
    }
    And now look at my code: (line 23)
    Java Code:
    import java.util.Scannner;
    public class Michs {
    	public static void main(String [] args) {
    	int c = 0;
    	Scanner scan = new Scanner (System.in);
    	System.out.printIn("XXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
    	System.out.printIn("X Witaj w programie Michs!  X");
    	System.out.printIn("XXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
    	System.out.printIn("X       JavaWER wer 0.1     X");
    	System.out.printIn("XXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
    	System.out.printIn("[1] Rozpocznij quiz");
    	System.out.printIn("[2] Wyjdz z programu");
    	String in;
    	in = scan.nextLine();
    	if(in.equals("1"))
    	{
    		int lidzba = 2;
    		System.out.printIn("Ile to jest 1+1?");
    		String in;
    		if(in.equals("2"));
    		{
    		System.out.printIn("Dobrze!");
          >>> } else {  <<<
    			 System.out.printIn("Zle! 1+1 to jest 2.");
    		}
    	}
    	}
    }
    Whats wrong?

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,433
    Blog Entries
    7
    Rep Power
    20

    Default Re: Problem witch "Illegal start of expression"

    The semi colon at line #20 doesn't belong there.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  7. #7
    thyks is offline Member
    Join Date
    Jun 2012
    Posts
    19
    Rep Power
    0

    Default Re: Problem witch "Illegal start of expression"

    Quote Originally Posted by JosAH View Post
    The semi colon at line #20 doesn't belong there.

    kind regards,

    Jos
    When I remove the semicolon in line 20, my makeshift compiler "puking" various errors (previously was an one error (else without if), and now there are fourteen!) Help!

  8. #8
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,433
    Blog Entries
    7
    Rep Power
    20

    Default Re: Problem witch "Illegal start of expression"

    Quote Originally Posted by thyks View Post
    When I remove the semicolon in line 20, my makeshift compiler "puking" various errors (previously was an one error (else without if), and now there are fourteen!) Help!
    And get rid of line #19.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  9. #9
    thyks is offline Member
    Join Date
    Jun 2012
    Posts
    19
    Rep Power
    0

    Default Re: Problem witch "Illegal start of expression"

    Quote Originally Posted by JosAH View Post
    And get rid of line #19.

    kind regards,

    Jos
    Thanks, but this don't helped me in this problem (else without if at line 23).
    And my question is:
    How to make this compiller shut up witch this stupid else without if? (without adding if to else)
    Last edited by thyks; 06-10-2012 at 09:56 PM. Reason: added a note

  10. #10
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Problem witch "Illegal start of expression"

    You need to code correctly if you want the compiler to "shut up", and it's very strict on what it will accept. Please show your latest code and error messages.

  11. #11
    thyks is offline Member
    Join Date
    Jun 2012
    Posts
    19
    Rep Power
    0

    Post Re: Problem witch "Illegal start of expression"

    Ok...
    Java Code:
    import java.util.Scannner;
    public class Michs {
    	public static void main(String [] args) {
    	int c = 0;
    	Scanner scan = new Scanner (System.in);
    	System.out.print("XXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
    	System.out.print("X Witaj w programie Michs!  X");
    	System.out.print("XXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
    	System.out.print("X       JavaWER wer 0.1     X");
    	System.out.print("XXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
    	System.out.print("[1] Rozpocznij quiz");
    	System.out.print("[2] Wyjdz z programu");
    	String in;
    	in = scan.nextLine();
    	if(in.equals("1"))
    	{
    		System.out.print("Ile to jest 1+1?");
    		if(in.equals("2"))
    			{System.out.print("Dobrze!");
            } else {
    			 System.out.print("Zle! 1+1 to jest 2.");
    		}
    	}
    	}
    }
    Errors:

    Java Code:
    michs.java:1: error: cannot find symbol
    import java.util.Scannner;
                    ^
      symbol:   class Scannner
      location: package java.util
    michs.java:5: error: cannot find symbol
            Scanner scan = new Scanner (System.in);
            ^
      symbol:   class Scanner
      location: class Michs
    michs.java:5: error: cannot find symbol
            Scanner scan = new Scanner (System.in);
                               ^
      symbol:   class Scanner
      location: class Michs
    michs.java:6: error: cannot find symbol
            System.out.printIn("XXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
                      ^
      symbol:   method printIn(String)
      location: variable out of type PrintStream
    michs.java:7: error: cannot find symbol
            System.out.printIn("X Witaj w programie Michs!  X");
                      ^
      symbol:   method printIn(String)
      location: variable out of type PrintStream
    michs.java:8: error: cannot find symbol
            System.out.printIn("XXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
                      ^
      symbol:   method printIn(String)
      location: variable out of type PrintStream
    michs.java:9: error: cannot find symbol
            System.out.printIn("X       JavaWER wer 0.1     X");
                      ^
      symbol:   method printIn(String)
      location: variable out of type PrintStream
    michs.java:10: error: cannot find symbol
            System.out.printIn("XXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
                      ^
      symbol:   method printIn(String)
      location: variable out of type PrintStream
    michs.java:11: error: cannot find symbol
            System.out.printIn("[1] Rozpocznij quiz");
                      ^
      symbol:   method printIn(String)
      location: variable out of type PrintStream
    michs.java:12: error: cannot find symbol
            System.out.printIn("[2] Wyjdz z programu");
                      ^
      symbol:   method printIn(String)
      location: variable out of type PrintStream
    michs.java:17: error: cannot find symbol
                    System.out.printIn("Ile to jest 1+1?");
                              ^
      symbol:   method printIn(String)
      location: variable out of type PrintStream
    michs.java:19: error: cannot find symbol
                            {System.out.printIn("Dobrze!");
                                       ^
      symbol:   method printIn(String)
      location: variable out of type PrintStream
    michs.java:21: error: cannot find symbol
                             System.out.printIn("Zle! 1+1 to jest 2.");
                                       ^
      symbol:   method printIn(String)
      location: variable out of type PrintStream
    13 errors
    Last edited by thyks; 06-11-2012 at 04:30 PM. Reason: Added a [code], because error log not show correctly without it

  12. #12
    thyks is offline Member
    Join Date
    Jun 2012
    Posts
    19
    Rep Power
    0

    Default Re: Problem witch "Illegal start of expression"

    Thanks all for the wasted time! I soluted my problem. But i have new problem... cannot find symbol...
    Java Code:
    import java.util.Scanner;
    import java.uti.;
    public class Michs {
        public static void main(String [] args) {
        int c = 0;
        Scanner input = new Scanner (System.in);
        System.out.print("XXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
        System.out.print("X Witaj w programie Michs!  X");
        System.out.print("XXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
        System.out.print("X       JavaWER wer 0.1     X");
        System.out.print("XXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
        System.out.print("[1] Rozpocznij quiz");
        System.out.print("[2] Wyjdz z programu");
        if(in.equals("1"))
        {
            System.out.print("Ile to jest 1+1?");
            if(in.equals("2"))
                {System.out.print("Dobrze!");
            }
    		else 
    		{
                 System.out.print("Zle! 1+1 to jest 2.");
            }
        }
        }
    }
    Error log:
    Michs.java:14: error: cannot find symbol
    in = scan.nextLine();
    .....^
    symbol: variable scan
    location: class Michs
    1 error
    Last edited by thyks; 06-11-2012 at 05:31 PM. Reason: Fixed code tags

  13. #13
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,433
    Blog Entries
    7
    Rep Power
    20

    Default Re: Problem witch "Illegal start of expression"

    What Java version do you have? (see with: "java -version")

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  14. #14
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,931
    Rep Power
    19

    Default Re: Problem witch "Illegal start of expression"

    Which line is line 14?
    I cannot see:
    in = scan.nextLine();

    anywhere, but the error implies that 'scan' has not been defined as a variable (your Scanner in the above code is called 'input').
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  15. #15
    thyks is offline Member
    Join Date
    Jun 2012
    Posts
    19
    Rep Power
    0

    Default Re: Problem witch "Illegal start of expression"

    Quote Originally Posted by JosAH View Post
    What Java version do you have? (see with: "java -version")

    kind regards,

    Jos
    Java version: 1.7.0_06-ea
    Java Se Runtime Environment: 1.7.0_06-ea-b12
    Java HoySpot 64 bit (i have 64 bit Win 7 Home Premium) Server VM: 23.2-b03, mixed mode

  16. #16
    thyks is offline Member
    Join Date
    Jun 2012
    Posts
    19
    Rep Power
    0

    Default Re: Problem witch "Illegal start of expression"

    Fixed line 14.
    But how to fix it? Can you give me fixed code? I don't know how to fix it.

  17. #17
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,931
    Rep Power
    19

    Default Re: Problem witch "Illegal start of expression"

    Fix what?
    Which errors are you now getting?
    And what does the code look like?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  18. #18
    thyks is offline Member
    Join Date
    Jun 2012
    Posts
    19
    Rep Power
    0

    Wink Re: Problem witch "Illegal start of expression"

    Quote Originally Posted by Tolls View Post
    Fix what?
    Which errors are you now getting?
    And what does the code look like?
    oh. I'm sorry, I fixed the same.
    Thanks all for the wasted time!
    Topic for removal!!!
    Last edited by Tolls; 06-12-2012 at 09:47 AM. Reason: edit shoutiness

  19. #19
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,931
    Rep Power
    19

    Default Re: Problem witch "Illegal start of expression"

    Please don't do that.
    We don't remove valid topics from here.
    This site is a resource whose value is largely in the threads it contains.
    If we were to remove those threads then we remove potential solutions for someone else.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  20. #20
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,433
    Blog Entries
    7
    Rep Power
    20

    Default Re: Problem witch "Illegal start of expression"

    Quote Originally Posted by thyks View Post
    Hello all, i have a problem witch my app (not first app).
    Code of the program:
    Java Code:
    import java.util.Scannner;
    public class Michs {
    	public static void main(String [] args) {
    	int c = 0;
    	Scanner scan = new Scanner (System.in);
    	System.out.printIn("XXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
    	System.out.printIn("X Witaj w programie Michs!  X");
    	System.out.printIn("XXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
    	System.out.printIn("X       JavaWER wer 0.1     X");
    	System.out.printIn("XXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
    	System.out.printIn("[1] Rozpocznij quiz");
    	System.out.printIn("[2] Wyjdz z programu");
    	String in;
    	in = scan.nextLine();
    	if(in.equals("1"))
    	{
    		int lidzba = 2;
    		System.out.printIn("Ile to jest 1+1?");
    		String in;
    		if(in.equals("2"));
    		{
    		System.out.printIn("Dobrze!");
    		}
            if (else);    <--------------- Heres the problem.  :(-:
            {
    		System.out.printIn("Zle! 1+1 to jest 2.");
    		}
    	}
    	}
    }
    i have my own compilator in batch:
    @echo off
    title kompilator
    set path=%path%;C:\Program Files\Java\jdk1.7.0\bin
    echo zalecana wersja jdk: 1.7.0
    echo umiesc ten program w folderze z plikiem .java!!!
    set /p war=co chesz skompilowac?
    javac %war%.java
    echo gotowe!
    pause
    exit
    Copied the OP, just in case ...

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. problem with illegal start of expression methdo
    By lathspell in forum New To Java
    Replies: 1
    Last Post: 12-15-2011, 05:29 PM
  2. Replies: 2
    Last Post: 10-03-2011, 06:22 PM
  3. Replies: 4
    Last Post: 05-27-2011, 08:21 AM
  4. Error: "Illegal start of expression"
    By mokitooo_1994 in forum New To Java
    Replies: 5
    Last Post: 05-12-2011, 09:42 PM
  5. "illegal start of expression"
    By 3RDofApril in forum AWT / Swing
    Replies: 2
    Last Post: 11-04-2010, 01:39 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •