Results 1 to 12 of 12
- 02-18-2012, 12:04 AM #1
Member
- Join Date
- Feb 2012
- Posts
- 12
- Rep Power
- 0
Simple code strangely not working..
here is the code, the class is there, i am getting the error of illegal start of expression..
why is this main method not working?Java Code:public static void main( String[] args ) { outputStupid( ); private static void outputStupid( ) { System.out.println( " stupid " ); } }Last edited by Norris80; 02-18-2012 at 12:16 AM. Reason: code tags added
-
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.
- 02-18-2012, 12:14 AM #3
Member
- Join Date
- Feb 2012
- Posts
- 12
- Rep Power
- 0
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..
- 02-18-2012, 12:20 AM #5
Member
- Join Date
- Feb 2012
- Posts
- 12
- Rep Power
- 0
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 " ); } }
-
Re: Simple code strangely not working..
- 02-18-2012, 12:24 AM #7
Member
- Join Date
- Feb 2012
- Posts
- 12
- Rep Power
- 0
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...
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..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 " ); } } }
- 02-18-2012, 12:28 AM #8
Member
- Join Date
- Feb 2012
- Posts
- 12
- Rep Power
- 0
Re: Simple code strangely not working..
okay, i think i know what i'm doing wrong now..
-
Re: Simple code strangely not working..
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]
Your main method starts at // A and ends at // D.Java Code:public static void main( String[] args ) // A { outputStupid( ); private static void outputStupid( ) // B { System.out.println( " stupid " ); } // C } // 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:
Make sense? Again if anything is confusing, please ask.Java Code:public static void main( String[] args ) // A { outputStupid( ); } // D private static void outputStupid( ) // B { System.out.println( " stupid " ); } // C }
-
Re: Simple code strangely not working..
- 02-18-2012, 12:33 AM #11
Member
- Join Date
- Feb 2012
- Posts
- 12
- Rep Power
- 0
-
Similar Threads
-
Data input stream behaving strangely
By werner291 in forum New To JavaReplies: 1Last Post: 01-01-2012, 06:39 PM -
Simple if code not working? Assistanc wanted.
By dunboody in forum New To JavaReplies: 6Last Post: 10-10-2011, 12:23 AM -
Simple servlet not working : entire source code posted
By rahulb in forum Java ServletReplies: 0Last Post: 05-24-2011, 07:50 AM -
actionPerformed acting strangely
By Fortu in forum New To JavaReplies: 18Last Post: 04-10-2011, 04:07 AM -
Simple code not working
By davetheant in forum New To JavaReplies: 7Last Post: 02-04-2011, 12:51 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks