Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 12-05-2009
Member
 
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!
Reply With Quote
  #2  
Old 12-05-2009
Member
 
Join Date: Feb 2008
Posts: 1,848
Re: "Identifier Expected" error in Dr Java

Check out the below link for more details.

Identifier Expected Error in JAVA
Reply With Quote
  #3  
Old 12-05-2009
Member
 
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.
Reply With Quote
  #4  
Old 12-05-2009
Member
 
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".
Reply With Quote
  #5  
Old 12-05-2009
Member
 
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.
Reply With Quote
  #6  
Old 12-05-2009
Member
 
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!
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: ""Identifier Expected" error in Dr Java"
Thread Thread Starter Forum Replies Last Post
<identifier> expected error mbueling Software Development 2 18-10-2011 06:04 AM
Excel Error message: "External table is not in the expected format" X-quisite Windows Software 4 29-11-2010 10:59 AM
<Identifier> Expected Error Circular Linked List Java JGriff254 Software Development 1 23-03-2010 02:25 PM
Identifier Expected Error in JAVA Brake Fail Software Development 7 25-10-2008 02:35 PM
Error "The expected version of the product was not found on your system" Domi.nick Office Update Service 2 08-12-2005 05:03 PM


All times are GMT +5.5. The time now is 08:48 AM.