• Post Reply Bookmark Topic Watch Topic
  • New Topic

illegal start of expression error  RSS feed

 
Khusbu Sinha
Ranch Hand
Posts: 117
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Why does this code throws the following error:
2 errors found:
File: E:\TestClass1.java  [line: 12]
Error: ']' expected
File: E:\TestClass1.java  [line: 12]
Error: illegal start of expression

 
Liutauras Vilda
Sheriff
Posts: 4917
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check lines: 9, 12
 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whenever you get multiple errors, you should only care about the first error.  Often the first error will confused the compiler and have it report other things that may or may not be errors.

So, it tells you to look at line 12. It even tells you WHERE on line 12 it thinks there is an error.  The little caret under the 'i' of "index".

So look at that line very carefully. What are you actually trying to do on that line?  Is what you have written how you actually do that?
 
Khusbu Sinha
Ranch Hand
Posts: 117
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I made the following change at line 12:



and it compiled successfully.

This means its declaration as 'String' was creating trouble.
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Khusbu Sinha wrote:
This means its declaration as 'String' was creating trouble.


Okay. And do you know why?

Henry
 
Khusbu Sinha
Ranch Hand
Posts: 117
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not exactly. I guess there was no need to declare the individual element of String[] as 'String' separately in this line.
 
Knute Snortum
Sheriff
Posts: 4276
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right.  You already have declared the array.  arrayOfStrings[index] is an element in that array, not a separate variable.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!