Results 1 to 6 of 6

Thread: "Identifier Expected" error in Dr Java

  1. #1
    Join Date
    May 2009
    Posts
    3

    "Identifier Expected" error in Dr Java

    I found some other threads about this same error but couldn't find anything that helped my specific case out. Anybody have any ideas? My assignment is to make a chatbot.
    I'm also getting a '(' expected error at the end of my list of 'if statements', but I've checked all parenthesis and they're all matched up. Any ideas on that?


    import java.util.Random;
    /**
    * Class to generate sentences
    * Adam Taylor
    */
    public class SentenceGenerator
    {
    private String[] nounArray = {"Josh", "Trent", "Kyle", "Megan", "Erin"};

    private String[] verbArray = {"jumped", "fell", "flew", "walked", "steps"};

    private String[] phraseArray = {"at a show", "in the back", "in a car",
    "in the street", "out the door"};

    private Random randGen = new Random();

    public String generateRandomSentence()
    {
    String sentence =
    nounArray[randGen.nextInt(nounArray.length)] + " " +
    verbArray[randGen.nextInt(verbArray.length)] + " " +
    phraseArray[randGen.nextInt(phraseArray.length)] + ".";
    return sentence;
    }

    public static void main(String[] args)
    {
    SentenceGenerator sentenceGen = new SentenceGenerator();
    for (int i=0; i<5; i++)
    {
    System.out.println(sentenceGen.generateRandomSentence());
    }
    }

    public void (String[])
    {
    if (input.indexOf("hello", "hi", "How are you?") >= 0)
    System.out.println("Hi, how are you doing today?");
    }





    Thanks so much for your time!

  2. #2
    Join Date
    Feb 2008
    Posts
    1,852

    Re: "Identifier Expected" error in Dr Java

    Check out the below link for more details.

    Identifier Expected Error in JAVA

  3. #3
    Join Date
    May 2008
    Posts
    3,971

    Re: "Identifier Expected" error in Dr Java

    Quote Originally Posted by adam.taylor View Post
    public void (String[])
    {
    if (input.indexOf("hello", "hi", "How are you?") >= 0)
    System.out.println("Hi, how are you doing today?");
    }
    I suppose your problem lies over here, you didn't defined any name to this function. It doesn't mean that if you have given the "public" and "void", your class or function is defined. You should give a unique name to it.

  4. #4
    Join Date
    May 2009
    Posts
    3

    Re: "Identifier Expected" error in Dr Java

    That thread was one of the ones I looked at. This stuff makes no sense to me so it's hard for me to relate someone else's problem to my own.

    I tried giving it a name but it still gives me the identifier error and it puts the cursor right after the brackets inside the parenthesis. If I don't give it a name, it puts the cursor right after "void".

  5. #5
    Join Date
    May 2008
    Posts
    3,971

    Re: "Identifier Expected" error in Dr Java

    Quote Originally Posted by adam.taylor View Post
    That thread was one of the ones I looked at. This stuff makes no sense to me so it's hard for me to relate someone else's problem to my own.

    I tried giving it a name but it still gives me the identifier error and it puts the cursor right after the brackets inside the parenthesis. If I don't give it a name, it puts the cursor right after "void".
    Its because you have not defined any variable inside the parenthesis. Just try declaring a variable and see if this works.

  6. #6
    Join Date
    May 2009
    Posts
    3

    Re: "Identifier Expected" error in Dr Java

    Okay, I passed a variable in the parenthesis and it got rid of that error. Now I have a whole slew of other errors haha. But I am going to tutoring tomorrow to try to get some help with those.

    Thanks for helping me out!

Similar Threads

  1. <identifier> expected error
    By mbueling in forum Software Development
    Replies: 2
    Last Post: 18-10-2011, 06:04 AM
  2. Replies: 4
    Last Post: 29-11-2010, 10:59 AM
  3. <Identifier> Expected Error Circular Linked List Java
    By JGriff254 in forum Software Development
    Replies: 1
    Last Post: 23-03-2010, 02:25 PM
  4. Identifier Expected Error in JAVA
    By Brake Fail in forum Software Development
    Replies: 7
    Last Post: 25-10-2008, 02:35 PM
  5. Replies: 2
    Last Post: 08-12-2005, 05:03 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,077,786.06665 seconds with 17 queries