Question: I am developing a game on Android that involves a grid of objects. Right now I am using an array to store the objects, like this:

```
public class ObjectBuffer {

  private final Object[] buffer;

  private final int playfieldWidth;

  ObjectBuffer(int playfieldWidth, int playfieldHeight) {
    super();
    this.buffer = new Object[playfieldWidth + (playfieldHeight * playfieldWidth)];
    this.playfieldWidth = playfieldWidth;
  }

  public static int getX(int id) {
    return id % playfieldWidth();
  }

  public static int getY(int id) {
    return id / playfieldWidth();
  }

  public Object get(int id) {
    return this.buffer[id];
  }

  public Object get(int x, int y) {
    return this.buffer[x + (y * this.playfieldWidth)];
  }
}

```

But, my questions is, is this the best way to accomplish this? I chose an array (as opposed to a list, ArrayList, or some other container) because once the width and height of the playfield are set, they do not change. The objects are there for state, and once they are instantiated and added to the array, they may be updated, but are not rearranged.

My question is similar to [Storing objects for locating by x,y coordinates](https://stackoverflow.com/questions/132319/storing-objects-for-locating-by-x-y-coordinates), but different enough that I wanted to ask my question separately. My requirements are different from his, and I don't think that a spatial index would be warranted in this situation. Please correct me if I'm wrong.

I should also mention, the array's dimensions will usually be 10x10 (100 elements), but may need to be able to accommodate a modest increase; but will not need to handle more than about a 15x15 grid (225 elements). These dimensions will always be known when generating the grid. After the grid has been generated, the dimensions will not change.

Answer: 
You're calling `type.getClass()` but at that point `type` is *guaranteed* to be null. No other code will have had a chance to set it yet, so how did you expect it to work? You say you're confused about why it's null - but you haven't shown anything which would make it non-null.

I suspect you want something like:

```
public abstract class ExcelReader<T>{
     protected final Class<T> type;
     protected GenericResolver resolver;

     public ExcelReader(Class<T> type){
        this.type = type;
        resolver = ResolverFactory.createResolver(type); 
     }
}

```

You'd want to introduce the same sort of parameter on the subclasses too.
You exactly explained the problem. The `type` is null. So, what do you have to do? Make it not null. Modify constructor as folloiwing:

```
 protected ExcelReader(T type){
    super();
    this.type = type;
    resolver=ResolverFactory.createResolver(type.getClass()); 
 }

```

Now your subclass must send this parameter, e.g. 

```
public class POIReader extends ExcelReader<MessageDTO>{
    public POIReader() {
        super(MessageDTO.class);
    }
}

```

Alternatively you can make your subclass generic too, so the responsibility on sending the type is moved to client:

```
public class POIReader<T> extends ExcelReader<T>{
    public POIReader(Class<T> type) {
        super(type);
    }
}

// and call it:
new POIReader(MessageDTO.class);

```