Issue calling superclass method in subclass constructor
        Posted  
        
            by stormin986
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by stormin986
        
        
        
        Published on 2010-04-30T19:34:58Z
        Indexed on 
            2010/05/08
            6:18 UTC
        
        
        Read the original article
        Hit count: 341
        
I get a NullPointerException calling a Superclass Method in Subclass Inner Class Constructor... What's the Deal?
In my application's main class (subclass of Application), I have a public inner class that simply contains 3 public string objects. In the parent class I declare an object of that inner class.
public class MainApplication extends Application {
    public class Data {
        public String x;
        public String y;
        public String z;
    }
    private Data data;
    MainApplication() {
        data = new Data()
        data.x = SuperClassMethod();
    }
}
After I instantiate the object in the constructor, I get a runtime error when I try to assign a value in the inner class with a superclass method.
Any idea what's up here?? Can you not call superclass methods in the subclass constructor?
** Edit ** Original question was about inner class member assignment in outer class constructor. Turned out the issue was with calling a superclass method in the class's constructor. It was giving me a null pointer exception. Thus, the question has changed.
© Stack Overflow or respective owner