Hi I'm trying to create an array of objects and then put a different value into each object. Problem is, I don't know why this isn't working.

public class TestProg2{
  public static void main(String args[]){
    Rank rank= new Rank();

class Rank{
private static int rankIndex=0;

public Rank(int enterRankIndex){ rankIndex=enterRankIndex; }

Rank [] ranks = new Rank [13];
for(i=0;i<ranks.length;i++) {
  ranks[i]=new Rank(i);
  System.out.println("create Rank marker:"+ranks[i]);

I keep getting these errors:
2 errors found:
File: /Volumes/LA-PUBLIC/TestProg2/TestProg2.java [line: 13]
Error: illegal start of type
File: /Volumes/LA-PUBLIC/TestProg2/TestProg2.java [line: 16]
Error: <identifier> expected

Your for() loop is not in a block. That code needs to be inside a constructor, method, or static initialization block.

Member Avatar

My guess would be...

public Rank(int enterRankIndex){ rankIndex=enterRankIndex; [B][U]}[/U][/B]

Well yes... that would be the character that caused the problem I tried to point out to him yesterday. Evidently the OP didn't care enough to return to the thread.

Member Avatar

Oh... Sorry...
I didn't really pick up on your intention.
My bad!

No worries, it may not have been clear at all to anyone else what I was getting at ;)