Results 1 to 12 of 12
  1. #1
    Norris80 is offline Member
    Join Date
    Feb 2012
    Posts
    12
    Rep Power
    0

    Default Simple code strangely not working..

    here is the code, the class is there, i am getting the error of illegal start of expression..

    Java Code:
        public static void main( String[] args )
        {
        	outputStupid( );
    
        	private static void outputStupid( )
        	{
        		System.out.println( " stupid " );
        	}
        }
    why is this main method not working?
    Last edited by Norris80; 02-18-2012 at 01:16 AM. 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: Simple code strangely not working..

    Count your opening and closing braces as it appears you have an opening brace for main but no closing brace. Either that or you're trying to nest a method inside of another method, and this is not allowed in Java.

    I've added [code] [/code] tags to your code to help make it readable.

  3. #3
    Norris80 is offline Member
    Join Date
    Feb 2012
    Posts
    12
    Rep Power
    0

    Default Re: Simple code strangely not working..

    i have a closing brace, wasn't included in copy and paste because i have a block of code not currently functing yet that i commented out.. all i'm testing right now is purely why that little block won't work

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

    Default Re: Simple code strangely not working..

    Quote Originally Posted by Norris80 View Post
    i have a closing brace, wasn't included in copy and paste because i have a block of code not currently functing yet that i commented out.. all i'm testing right now is purely why that little block won't work
    We need to see that closing brace. If it is present after the code above, then it appears that you're trying to nest methods -- have one method inside of another -- and this is not legal in Java.

  5. #5
    Norris80 is offline Member
    Join Date
    Feb 2012
    Posts
    12
    Rep Power
    0

    Default Re: Simple code strangely not working..

    i moved the curly brace in the code to be next to the one method i'm trying to run, still receiving the same error of illegal start of expression

    Java Code:
    public static void main( String[] args )
        {
        	outputStupid( );
    
        	private static void outputStupid( )
        	{
        		System.out.println( " stupid " );
        	}
        }

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

    Default Re: Simple code strangely not working..

    Quote Originally Posted by Norris80 View Post
    i moved the curly brace in the code to be next to the one method i'm trying to run, still receiving the same error of illegal start of expression

    Java Code:
    public static void main( String[] args )
        {
        	outputStupid( );
    
        	private static void outputStupid( )
        	{
        		System.out.println( " stupid " );
        	}
        }
    I've explained the cause of your problem above. Please re-read my posts above, and let me know if anything is not clear.

  7. #7
    Norris80 is offline Member
    Join Date
    Feb 2012
    Posts
    12
    Rep Power
    0

    Default Re: Simple code strangely not working..

    okay, either I'm not understanding what you are telling me what I'm doing wrong, or there is something else, so i created a new java file with the only code in it as this...

    Java Code:
    /**
     * @(#)TestingJCreator.java
     *
     *
     * @author
     * @version 1.00 2012/2/17
     */
    
    
    public class TestingJCreator
    {
    
        public static void main( String[] args )
        {
        	outputStupid( );
    
        	private static void outputStupid( )
        	{
        		System.out.println( " stupid " );
        	}
        }
    }
    and i'm still receiving the same error of illegal start of expression, and this is exact same code my professor performed in class and it worked, so idk what's going wrong..

  8. #8
    Norris80 is offline Member
    Join Date
    Feb 2012
    Posts
    12
    Rep Power
    0

    Default Re: Simple code strangely not working..

    okay, i think i know what i'm doing wrong now..

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

    Default Re: Simple code strangely not working..

    Quote Originally Posted by Norris80 View Post
    okay, either I'm not understanding what you are telling me what I'm doing wrong, ...
    I may not be explaining it well enough, but the code you've posted is clear, and hopefully I can use it to explain myself better.

    Here's a portion of your code:

    [code]
    Java Code:
        public static void main( String[] args ) // A
        {
        	outputStupid( );
    
        	private static void outputStupid( ) // B
        	{
        		System.out.println( " stupid " );
        	} // C
        } // D
    }
    Your main method starts at // A and ends at // D.
    Inside of this method you have another method, the outputStupid() method that starts at // B and ends at // C.

    By doing this you are nesting one method (outputStupid) inside of another method (main), and this is simply not allowed in Java. The solution is to take outputStupid, remove it from the main method and place it either before or after the main method:


    Java Code:
        public static void main( String[] args ) // A
        {
        	outputStupid( );
        } // D
    
        private static void outputStupid( ) // B
        {
            System.out.println( " stupid " );
        } // C
    
    }
    Make sense? Again if anything is confusing, please ask.

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

    Default Re: Simple code strangely not working..

    Quote Originally Posted by Norris80 View Post
    okay, i think i know what i'm doing wrong now..
    Ah, I just wasted some energy, oh well, as long as this problem is solved as that's what really matters.

  11. #11
    Norris80 is offline Member
    Join Date
    Feb 2012
    Posts
    12
    Rep Power
    0

    Default Re: Simple code strangely not working..

    Quote Originally Posted by Fubarable View Post
    Ah, I just wasted some energy, oh well, as long as this problem is solved as that's what really matters.
    Yea, thanks for helping, at first i didn't understand what you meant by putting a method inside the main, then all of sudden it clicked, thank you

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

    Default Re: Simple code strangely not working..

    You're welcome, and best of luck!

Similar Threads

  1. Data input stream behaving strangely
    By werner291 in forum New To Java
    Replies: 1
    Last Post: 01-01-2012, 07:39 PM
  2. Simple if code not working? Assistanc wanted.
    By dunboody in forum New To Java
    Replies: 6
    Last Post: 10-10-2011, 01:23 AM
  3. Replies: 0
    Last Post: 05-24-2011, 08:50 AM
  4. actionPerformed acting strangely
    By Fortu in forum New To Java
    Replies: 18
    Last Post: 04-10-2011, 05:07 AM
  5. Simple code not working
    By davetheant in forum New To Java
    Replies: 7
    Last Post: 02-04-2011, 01:51 AM

Posting Permissions

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