从java中的子类访问实例变量

时间:2012-05-10 13:45:55

标签: java

这是我的超类

package ruleta;
import wheels.Wheel;

public class Resolving{

private int nummerCases;    
private int[][] forbidenCases;
protected int[] initialConfiguration;
protected int[] targetConfiguration;


public Resolving(){
}

public Resolving(int[][] obj, int nummer){
    this.forbidenCases = obj;
    this.nummerCases = nummer;
}

protected void setiConfiguration(int[] array){
    this.initialConfiguration = array;
}

protected int[] getiConfiguration(){
    return initialConfiguration;
}

protected void settConfiguration(int[] array){
    this.targetConfiguration = array;
}

protected int[] gettConfiguration(){
    return this.targetConfiguration;
}

public void run(){

    setiConfiguration(forbidenCases[0]);
    settConfiguration(forbidenCases[1]);

    for(int i=0;i<4;i++){
        System.out.println(initialConfiguration[i]);
    }

    Wheel roulette = new Wheel();

}   
}

问题是,为什么如果我从超类(Resolving)访问实例变量,它总是返回值null? 试图这样做:final int[] iC = super.getiConfiguration();它返回我:

Exception in thread "main" java.lang.NullPointerException
    at wheels.Wheel.<init>(Wheel.java:32)
    at ruleta.Resolving.run(Resolving.java:60)
    at ruleta.Resolving.<init>(Resolving.java:30)
    at ruleta.Arguments.runningFunction(Arguments.java:111)
    at ruleta.Arguments.<init>(Arguments.java:15)
    at main.Main.main(Main.java:7)

我不知道是不是因为我,我还不太了解继承Java系统。谢谢

0 个答案:

没有答案