Results 1 to 10 of 10
  1. #1
    vickyv200 is offline Member
    Join Date
    Aug 2012
    Posts
    6
    Rep Power
    0

    Default Error: Identifier Expected

    It applies to line 20.

    When I put main after void, it gives me another error that says method main already defined in class (____) What can I put after void to stop the compile error and make it so the lines after it show up?
    //NAME
    //CLASS
    //SEMESTER
    //PROJECT NAME

    public class mynameincode{

    public static void main(String[]args) {
    PrinHeading();
    }

    public static void PrinHeading () {

    System.out.println ("name");
    System.out.println ("Class");
    System.out.println ("semester");
    System.out.println ("project name");
    }

    public static void main (String[]args) {

    System.out.println("garbage");
    System.out.println("garbage");
    System.out.println("garbage");
    System.out.println("garbage");
    System.out.println("garbage");
    System.out.println("garbage");
    System.out.println("garbage");

    }

    }
    Last edited by vickyv200; 08-29-2012 at 10:35 PM.

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default Re: Error: Identifier Expected

    What can I put after void to stop the compile error and make it so the lines after it show up?
    Your class has duplicate method definitions (eg main). Create unique method names/definitions

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

    Default Re: Error: Identifier Expected

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

  4. #4
    vickyv200 is offline Member
    Join Date
    Aug 2012
    Posts
    6
    Rep Power
    0

    Default Re: Error: Identifier Expected

    Quote Originally Posted by doWhile View Post
    Your class has duplicate method definitions (eg main). Create unique method names/definitions
    Ok, I changed the second main to secondary, now it compiles, but the lines after it will not print. Just the print heading.
    So it looks like

    name
    Class
    Semester
    project name

    But the lines after that won't print.
    Last edited by vickyv200; 08-31-2012 at 12:35 AM.

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

    Default Re: Error: Identifier Expected

    What "lines after" are you talking about? Your code as written will only print what you see. Perhaps you should post your updated code and explain what you're trying to do.

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

    Default Re: Error: Identifier Expected

    Please post your code here. You're asking for free advice, so please try to make it as easy as possible to help you. Also again, please let us know what you expect the output to be.

  7. #7
    vickyv200 is offline Member
    Join Date
    Aug 2012
    Posts
    6
    Rep Power
    0

    Default Re: Error: Identifier Expected

    Alright I'm not sure what the problem is with the actual java file.
    I expect the output to be 7 lines of the word garbage.
    Java Code:
    //NAME
    //CLASS
    //SEMESTER
    //PROJECT NAME
    
    public class boo{
    
    public static void main(String[]args) {
    PrinHeading();
    }
    
    public static void PrinHeading () {
    
    System.out.println ("name");
    System.out.println ("Class");
    System.out.println ("semester");
    System.out.println ("project name");
    }
    
    public static void secondary (String[]args) {
    //Everything after this won't show up, only the print heading.
    
    System.out.println("garbage");
    System.out.println("garbage");
    System.out.println("garbage");
    System.out.println("garbage");
    System.out.println("garbage");
    System.out.println("garbage");
    System.out.println("garbage");
    
    }
    
    }
    Last edited by vickyv200; 08-31-2012 at 09:13 AM.

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

    Default Re: Error: Identifier Expected

    Walk through each line of your program as if it were running to get the flow of its logic, starting with the main method. You're asking why the code in the secondary method never gets called. Ask yourself as you're waking through your code -- "where do I call this method?"

  9. #9
    vickyv200 is offline Member
    Join Date
    Aug 2012
    Posts
    6
    Rep Power
    0

    Default Re: Error: Identifier Expected

    Quote Originally Posted by Fubarable View Post
    Walk through each line of your program as if it were running to get the flow of its logic, starting with the main method. You're asking why the code in the secondary method never gets called. Ask yourself as you're waking through your code -- "where do I call this method?"
    If I call it before the print heading doesn't show up.

  10. #10
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,942
    Rep Power
    19

    Default Re: Error: Identifier Expected

    We can't see your code here, or your output, so what does "If I call it before the print heading doesn't show up" mean?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. <identifier expected> error. please help!
    By christopherx in forum AWT / Swing
    Replies: 9
    Last Post: 10-02-2011, 10:23 PM
  2. Error:identifier expected(Help!)
    By chhoton in forum New To Java
    Replies: 8
    Last Post: 09-22-2009, 04:42 PM
  3. getting identifier expected error . help me !
    By victorkeath in forum New To Java
    Replies: 3
    Last Post: 11-07-2008, 05:49 PM
  4. Identifier expected error
    By vasu18 in forum New To Java
    Replies: 1
    Last Post: 01-01-2008, 05:49 PM
  5. Error: <identifier> expected
    By barney in forum AWT / Swing
    Replies: 2
    Last Post: 07-31-2007, 07:38 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
  •