日期:2014-05-20 浏览次数:20880 次
class ClassA { public void methodA() { ClassB classB = new ClassB(); classB.getValue(); } } class ClassB { public ClassC classC; public String getValue() { return classC.getValue(); } } class ClassC { public String value; public String getValue() { value = "ClassB"; return value; } } public class Question { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub ClassA a = new ClassA(); a.methodA(); } } //Exception in thread "main" java.lang.NullPointerException // at ClassB.getValue(Question.java:11) // at ClassA.methodA(Question.java:4) // at Question.main(Question.java:31)