我有以下课程:https://paste.md-5.net/mozodifaka.java
我一直在第281行获得NPE。我一直在弄弄它好几个小时了,但我无法使它正常工作。您可以清楚地看到我正在使用landList = new ArrayList<>()
对其进行初始化,因此landList
仍然为空吗?
public class Kingdom extends OfflineKingdom implements KingdomEventHandler {
private transient volatile List<KingdomPlayer> onlineMembers;// = new ArrayList<>();
private transient volatile List<Kingdom> onlineEnemies;// = new ArrayList<>();
private transient volatile List<Kingdom> onlineAllies;// = new ArrayList<>();
private transient volatile int kingdomLand;// = 0;
private transient volatile List<Land> landList;// = new ArrayList<>();
private transient volatile int uptime;// = 2;
private transient volatile Kingdom invader;
private transient volatile Kingdom invading;
private transient volatile long invasionStart;
volatile Location nexus_loc;
volatile Location home_loc;
volatile int chestsize;// = 9;
volatile long timestamp;// = 0;
volatile int maxMember;// = 10;
ChampionInfo championInfo;// = new ChampionInfo();
PermissionsInfo permissionsInfo;// = new PermissionsInfo();
ArmyInfo armyInfo;// = new ArmyInfo();
AggressorInfo aggressorInfo;// = new AggressorInfo();
MisupgradeInfo misupgradeInfo;// = new MisupgradeInfo();
KingdomChest kingdomChest;// = new KingdomChest();
PowerUp powerUp;// = new PowerUp();
TurretUpgradeInfo turretUpgrades;// = new TurretUpgradeInfo();
private boolean init = false;
{
onlineMembers = new ArrayList<>();
onlineEnemies = new ArrayList<>();
onlineAllies = new ArrayList<>();
kingdomLand = 0;
landList = new ArrayList<>();
uptime = 2;
chestsize = 9;
timestamp = 0;
maxMember = 10;
championInfo = new ChampionInfo();
permissionsInfo = new PermissionsInfo();
armyInfo = new ArmyInfo();
aggressorInfo = new AggressorInfo();
misupgradeInfo = new MisupgradeInfo();
kingdomChest = new KingdomChest();
powerUp = new PowerUp();
turretUpgrades = new TurretUpgradeInfo();
init = true;
}
public Kingdom(String kingdomName) {
super(kingdomName);
}
public void init() {
if (init == (init = true)) return;
onlineMembers = new ArrayList<>();
onlineEnemies = new ArrayList<>();
onlineAllies = new ArrayList<>();
kingdomLand = 0;
landList = new ArrayList<>();
uptime = 2;
chestsize = 9;
timestamp = 0;
maxMember = 10;
championInfo = new ChampionInfo();
permissionsInfo = new PermissionsInfo();
armyInfo = new ArmyInfo();
aggressorInfo = new AggressorInfo();
misupgradeInfo = new MisupgradeInfo();
kingdomChest = new KingdomChest();
powerUp = new PowerUp();
turretUpgrades = new TurretUpgradeInfo();
}
public int getLand() {
init();
int land = 0;
for (final Land l : LandManager.landList.values()) {
if (l.getOwner() == null || !l.getOwner().equals(getKingdomName())) continue;
landList.add(l); // 281
land++;
}
return land;
}
public List<Land> getLandList() {
getLand();
return landList;
}
}
答案 0 :(得分:1)
您正在寻找错误的ArrayList
实例。
LandManager.landList
这是来自另一类List
的静态 LandManager
。
您要初始化的对象位于Kingdom
内部。
landList = new ArrayList<>();