Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2011
    Posts
    12
    Rep Power
    0

    Unhappy Why does this give me an error?

    if(choice1.equals ("0"))
    MainMenu();
    else if(choice1.equals("Hello"))
    System.out.println("Conversation initiated.");
    Conversation();
    else
    System.out.println("Sorry? Reverting to main menu.");
    MainMenu();

    I don't understand where my error is. If I delete the word Conversation(); , the error goes away, but then I don't have a way to initiate my Conversation function. Any help?

  2. #2
    Vase is offline Member
    Join Date
    Jan 2011
    Location
    Gainesville, FL
    Posts
    45
    Rep Power
    0

    Default

    You can either have a single statement or a block within an "if".

    Single statement:
    Java Code:
    if (true)
       statement;

    Block:
    Java Code:
    if (true) {
       statement1;
       statement2;
       statement3;
    }

  3. #3
    Join Date
    Feb 2011
    Posts
    12
    Rep Power
    0

    Default

    Thanks, that helped me out. I managed to leave out the curly brackets.

  4. #4
    Junky's Avatar
    Junky is online now Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,760
    Rep Power
    7

    Default

    Always use braces around if statements and loops even if you do not need them. Just to avoid problems like this.

  5. #5
    Join Date
    Feb 2011
    Posts
    12
    Rep Power
    0

Similar Threads

  1. Can YOU give me a project to do?
    By AcousticBruce in forum New To Java
    Replies: 8
    Last Post: 03-26-2011, 05:12 AM
  2. when i build my project it give following error
    By enggvijaysingh@gmail.com in forum Advanced Java
    Replies: 0
    Last Post: 11-18-2010, 11:02 AM
  3. I need some one to give me a hand
    By HosHos in forum Advanced Java
    Replies: 9
    Last Post: 09-05-2009, 03:18 PM
  4. how to give delay?
    By shaluchandran in forum New To Java
    Replies: 10
    Last Post: 12-17-2008, 05:57 PM
  5. Please give me a solution
    By ivvgangadhar in forum AWT / Swing
    Replies: 5
    Last Post: 11-14-2008, 01:43 PM

Posting Permissions

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