我非常肯定,命名对象不会像
那样改变它A a = new A();
A b = new A();
第二个对象应具有与第一个对象完全相同的属性。所以这是我的编码问题
public class Animation {
public static final Animation MOROTE_SEOI_NAGE = new Animation(JudokaComponent.MOROTE1, JudokaComponent.MOROTE2, JudokaComponent.MOROTE3);
public static final Animation morote_seoi_nage = new Animation(JudokaComponent.judokaStanding1, JudokaComponent.judokaStanding2, JudokaComponent.judokaStanding1);
public static final Animation UCHI_MATA = new Animation(JudokaComponent.uchiMata1, JudokaComponent.uchiMata2, JudokaComponent.uchiMata3);
public static final Animation uchi_mata = new Animation(JudokaComponent.judokaStanding1, JudokaComponent.judokaStanding2, JudokaComponent.judokaStanding1);
public static final Animation O_SOTO_GARI = new Animation(JudokaComponent.oSotoGari1, JudokaComponent.oSotoGari2, JudokaComponent.oSotoGari3);
public static final Animation Lel = new Animation(JudokaComponent.oSotoGari1, JudokaComponent.oSotoGari2, JudokaComponent.oSotoGari3);
public static final Animation o_soto_gari = new Animation(JudokaComponent.judokaStanding1, JudokaComponent.judokaStanding2, JudokaComponent.judokaStanding1);
public int ID;
public BufferedImage[] SPRITES;
public Animation(BufferedImage step1, BufferedImage step2, BufferedImage step3){
if(step1 == null || step2 == null || step3 == null) {
if(step1 == null) System.err.print("Step 1 was NPE. Address: " + this + "\n");
if(step2 == null) System.err.print("Step 2 was NPE. Address: " + this + "\n");
if(step3 == null) System.err.print("Step 3 was NPE. Address: " + this + "\n");
throw new RuntimeException("Animation NEP");
}
BufferedImage[] SPRITES = {step1, step2, step3};
this.SPRITES = SPRITES;
}
}
在这里更具体的theese线:
public static final Animation O_SOTO_GARI = new Animation(JudokaComponent.oSotoGari1, JudokaComponent.oSotoGari2, JudokaComponent.oSotoGari3);
public static final Animation Lel = new Animation(JudokaComponent.oSotoGari1, JudokaComponent.oSotoGari2, JudokaComponent.oSotoGari3);
对我而言,它们看起来像是完全相同的对象,但名称不同。当我运行没有O_SOTO_GARI对象的代码时,它按预期工作,至少是启动。但是,一旦我取消评论O_SOTO GARI对象的创建,我就会在游戏开始之前得到这个输出:
Step 1 was NPE. Address: com.kruhlmann.judoka.graphics.Animation@184ec44
Step 2 was NPE. Address: com.kruhlmann.judoka.graphics.Animation@184ec44
Step 3 was NPE. Address: com.kruhlmann.judoka.graphics.Animation@184ec44
Exception in thread "main" java.lang.ExceptionInInitializerError
但为什么呢?如果我制作完全相同的对象并称之为“Lel”,我不会收到此错误。为什么会这样,我很困惑