• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Error message: illegal start of type

 
Rancher
Posts: 688
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

my code:-

for (int i = 0;i < 4;i++) {
some code here .........
}

error message:-

illegal start of type

cannot find symbol
symbol: class j
location: AAA (name of program)

<identifier expected>

Unsure what is wrong here?

Bob M
 
Bartender
Posts: 2236
63
IntelliJ IDE Firefox Browser Spring Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please, UseCodeTags.

The compiler can't find a class named j you are trying to use.
Unfortunately you didn't show us the code that uses j.
 
Bob Matthews
Rancher
Posts: 688
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry..............

 
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should not be calling classes things like j or AAA.
It is possible that j is in such a position that the compiler thinks it is a class name, but you have got it out of position and it is not supposed to be a class name.
 
Paweł Baczyński
Bartender
Posts: 2236
63
IntelliJ IDE Firefox Browser Spring Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also, take a look at line 3. Do you see an error there?
 
Bob Matthews
Rancher
Posts: 688
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Campbell

You have hit the nail on the head...................

I wish j to be an integer - not a class name

What do I do to stop the compiler thinking it is a class name ?

and yes..... I missed an "=" in line 3

I used "AAA" for simplicity - it represents the name of the java program

Bob M
 
Paweł Baczyński
Bartender
Posts: 2236
63
IntelliJ IDE Firefox Browser Spring Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't see anything wrong in your code regarding the identifier j.

The compiler will show you in which line it thinks there is a problem. Show us the code near that line.
 
Bob Matthews
Rancher
Posts: 688
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Pawel

I am getting the error on line 1 of my code

Bob M
 
Paweł Baczyński
Bartender
Posts: 2236
63
IntelliJ IDE Firefox Browser Spring Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And what is this line 1? Can you show us?
Line 1 is usually a package statement.
Or an import if you use default package.
Or a class declaration if you use default package and don't use imports.

Do you have a class named j in your project?
 
Campbell Ritchie
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You will by now have seen that class names like AAA do not produce simplicity, but confusion.
Have you written
import j ava.util.Something;
by mistake?
 
Marshal
Posts: 8857
637
Mac OS X VI Editor BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And beside what you have been told already about confusing class name, you should spend more time on choosing all other variable names. Also, follow right Java naming convention. Moreover - format code properly, as line 6 suppose to be shifted by 4 spaces to the right hand side, actually the same as line 2. To conclude this - in your code is more confusion than clarity. Please take seriously what you have been told in posts above, as these bad habbits from the early time leads to a bad practices and error prone code.
 
Bob Matthews
Rancher
Posts: 688
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks to everybody for your helpful comments

Bob M
 
Bartender
Posts: 689
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which method is the code you have posted inside of? I suspect you have placed that code in a location it is not allowed to be.

Post your whole class here (everything in that file).
reply
    Bookmark Topic Watch Topic
  • New Topic