Results 1 to 3 of 3
Like Tree2Likes
  • 2 Post By quad64bit

Thread: "Illegal start of expression", What does this mean?

  1. #1
    JavaDog97 is offline Member
    Join Date
    Nov 2012
    Posts
    4
    Rep Power
    0

    Default "Illegal start of expression", What does this mean?

    Hey guys,

    I was writing code for my Hello World HTML Applet and when I compiled it in my cmd, it gave me the errors...

    HelloWorld.java:8: error: illegal start of expression
    private Font a_Font

    HelloWorld.java:11: error: illegal start of expression
    public void init()

    HelloWorld.java:11: error: illegal start of expression
    public void init()

    HelloWorld.java:11: error: illegal start of expression
    public void ()


    Java Code:
    import java.applet.*;
    import java.awt.*;
    
        public class HelloWorld extends Applet
        {
            public void paint (Graphics g)
            {
                private Font a_Font;
                g.setColor (Color.blue);
                
                public void init()
                {   
                    a_Font = new Font("Helvetica", Font.BOLD, 48);
                    setFont(a_Font);
                    setBackground(Color.yellow);
                    setForeground(Color.blue);
                }
                
                g.drawString("Hello World", 50, 25);
                
                g.setColor(Color.red);
                g.drawRect (5,8,49,29);
                    
                
                
            }
        }
    Any interpretations as to what might be the problem? Sorry for the basic problem, not good with errors in java...

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

    Default Re: "Illegal start of expression", What does this mean?

    You've got code either in the wrong place or written incorrectly. Already I see you've got methods nested inside of methods, you're declaring variables as private inside of methods which is illegal....

    The biggest mistake I see is that you have more than one of these errors present which mean that you are coding wrong. You need to start with the barest skeleton of code, and first make sure that it compiles. Then when adding code if you're not using an IDE you must compile often, usually after adding each line or two of code, and don't add any new code until the current code compiles well.

  3. #3
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default Re: "Illegal start of expression", What does this mean?

    You can;t declare the scope of a local variable, local variables are just local. Remove the word 'private'. Also you tried to declare the init() method inside the paint method, and you cannot do that!
    Fubarable and Jingoism like this.

Similar Threads

  1. Problem witch "Illegal start of expression"
    By thyks in forum New To Java
    Replies: 19
    Last Post: 06-12-2012, 11:06 AM
  2. Replies: 2
    Last Post: 10-03-2011, 07:22 PM
  3. Replies: 4
    Last Post: 05-27-2011, 09:21 AM
  4. Error: "Illegal start of expression"
    By mokitooo_1994 in forum New To Java
    Replies: 5
    Last Post: 05-12-2011, 10:42 PM
  5. "illegal start of expression"
    By 3RDofApril in forum AWT / Swing
    Replies: 2
    Last Post: 11-04-2010, 02: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
  •