【发布时间】:2015-12-30 10:15:39
【问题描述】:
我希望我的程序输入另一个类的私有变量。
我想使用 mutator 和 accessor。
它不断出错 NullPointerException。我的代码有什么问题?
public abstract class Inputs {
private String val;
private String typ;
public abstract void setVal(String val);
public abstract void setTyp(String typ);
public abstract String getVal();
public abstract String getTyp();
}
public DeckOfCards extends Inputs{
String val;
String typ;
static DeckOfCards kerds = new DeckOfCards();
public void setVal(String val){
this.val = val;
}
public void setTyp(String typ){
this.typ = typ;
}
public String getVal(){
return this.val;
}
public String getTyp(){
return this.typ;
}
public static void main(String args[]){
System.out.print("Value: ");
kerds.setVal(kerds.val);
if(kerds.val.equals("A"){
System.out.print("Type: ");
kerds.setTyp(kerds.typ);
}
}
}
【问题讨论】:
-
你的堆栈跟踪在哪里?
-
什么是堆栈跟踪?
-
控制台中的完整错误:stackoverflow.com/questions/3988788/…
标签: java inheritance accessor mutators