所以我有这个代码,
static File overlay1 = new File(Minecraft.getMinecraft().mcDataDir, "\\TVMod\\Pictures\\" + pictureList[0].getName());
但是当我运行该代码时,我得到一个NullPointerException,因为pictureList [0]不存在。但我希望它只在pictureList [0]存在时才能生成变量。我希望我能很好地解释这一点
答案 0 :(得分:0)
static{
if (pictureList != null && pictureList.length>0)
overlay1 = new File(Minecraft.getMinecraft().mcDataDir, "\\TVMod\\Pictures\\" + pictureList[0].getName());
}
static File overlay1;