Simple code strangely not working..
here is the code, the class is there, i am getting the error of illegal start of expression..
Code:
public static void main( String[] args )
{
outputStupid( );
private static void outputStupid( )
{
System.out.println( " stupid " );
}
}
why is this main method not working?
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.
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
Re: Simple code strangely not working..
Quote:
Originally Posted by
Norris80
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.
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
Code:
public static void main( String[] args )
{
outputStupid( );
private static void outputStupid( )
{
System.out.println( " stupid " );
}
}
Re: Simple code strangely not working..
Quote:
Originally Posted by
Norris80
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
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.
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...
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..
Re: Simple code strangely not working..
okay, i think i know what i'm doing wrong now..
Re: Simple code strangely not working..
Quote:
Originally Posted by
Norris80
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]
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:
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.
Re: Simple code strangely not working..
Quote:
Originally Posted by
Norris80
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.
Re: Simple code strangely not working..
Quote:
Originally Posted by
Fubarable
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
Re: Simple code strangely not working..
You're welcome, and best of luck!