让我们开始谈正事吧。我有这行代码:
public static Tile[] tiles = new Tile[400];
这在 eclipse 中给了我以下错误
Syntax error on token ";", { expected after this token
Tile 是同一个项目和包中的一个类,我想为其创建一个数组,因为我想不出任何其他方法来完成程序其余部分中的事情......
我在谷歌和stackoverflow上看过,但找不到答案。有人可以向我解释我做错了什么吗?
在此先感谢,德克。
编辑:这是瓷砖类:
package com.mrdls.invade;
public class Tile {
public String name = "";
public int id = 0;
public boolean passable = false;
public Tile(String name, int id){
this.name = name;
this.id = id;
if(name == "air"){
passable = true;
}
}
}
EDIT2,这里是 TilesBlocks 类
package com.mrdls.invade;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
public class TilesBlocks {
public static BufferedImage tilesetBlocks;
public static int pixelsPerTile = 20;
public int[] ints = new int[20];
public Tile[] tiles = new Tile[400];
tiles[0] = new Tile("air", -1);
/*public static final Tile earth = new Tile("earth", 0);
public static final Tile stone = new Tile("stone", 1);
public static final Tile cobblestone = new Tile("cobblestone", 2);
public static final Tile sand = new Tile("sand", 3);
public static final Tile sandstone = new Tile("sandstone", 4);
public static final Tile grass = new Tile("grass", 5);
public static final Tile woodLog = new Tile("log", 6);
public static final Tile leaves = new Tile("leaves", 7);
public static final Tile pumpkin = new Tile("pumpkin", 8);
public static final Tile melon = new Tile("melon", 9);
public static final Tile pumpkinCarved = new Tile("carved pumpkid", 10);
public static final Tile copperOre = new Tile("copper ore", 20);
public static final Tile tinOre = new Tile("tin ore", 21);
public static final Tile ironOre = new Tile("iron ore", 22);
public static final Tile silverOre = new Tile("silver ore", 23);
public static final Tile goldOre = new Tile("gold ore", 24);
public static final Tile diamondOre = new Tile("diamond ore", 40);
public static final Tile emeraldOre = new Tile("emerald ore", 41);
public static final Tile rubyOre = new Tile("ruby ore", 42);
public static final Tile sapphireOre = new Tile("sapphire ore", 43);*/
public TilesBlocks(){
try{
TilesBlocks.tilesetBlocks = ImageIO.read(Tile.class.getResourceAsStream("/tileset_terrain.png"));
}catch(Exception e){
}
}
}