File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Constructor confusion... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Constructor confusion..." Watch "Constructor confusion..." New topic
Author

Constructor confusion...

Jennifer Sohl
Ranch Hand

Joined: Feb 28, 2001
Posts: 455
Hi again. Boy am I confused! I have created a base class and a subclass. The base class is OrderMaintenance and the subclass is NewOrder. Believe it or not, this is the first time I have extended one of my own classes, and I'm having a hard time with it.
I created a default constructor for the OrderMaintenance class as well as one that takes arguments. When I create an object of OrderMaintenance, I pass the appropriate arguments to the constructor. Now when I try to run my application, I keep getting a "NullPointerException" on any objects that should have been created in the OrderMaintenance constructor.
I've read other posts, but still can't seem to figure out what I've done wrong.
Here's what I'm doing:
This is where OrderMaintenance is created...

This is what the constructors for OrderMaintenance look like:

// Here's part of the NewOrder class...(that is the subclass)...

I know I'm doing something horribly wrong, (maybe because I'm not sure exactly what I'm doing) but I don't know what. What do I need to code to make this scenario work? (I'm this close to becoming a procedural programmer again)
Could someone please straighten me out?? I feel really stupid right now.
Thanks in advance.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Problem I am having is the partial code. It seems there are vairables or objects in your code segments that haven't been defined anywhere. I am sure this is because you have left that part of the code out.
If you could, could you post where exactly you are getting the NullPointerException? Without that it is hard for me to determine where the error may lie.
Someone else might be able to though


GenRocket - Experts at Building Test Data
Jennifer Sohl
Ranch Hand

Joined: Feb 28, 2001
Posts: 455
Here's all the code for the NewOrderTab class (which is where the NullPointerException is pointing to).
Sorry about my code. I know it could probably have been coded a lot better, but I'm still learning. Once I get this working, I will try and make it better. (But that's another day!).
Here it goes... (I've put a comment line in the code where the NullPointerException is occurring)...

Thanks again!
[ So, it must be that Jennifer works for the dark side with big monitors... ]
[ September 11, 2002: Message edited by: Dirk Schreckmann ]
Dave Landers
Ranch Hand

Joined: Jul 24, 2002
Posts: 401
I didn't look at the whole thing, but I noticed that your base class has a field named "con" and your subclass also has a field named "con". I bet you have done that for several fields.
You don't want to do this - you actually have two fields named "con" and (without going into all the details which a good basic java book or tutorial could explain better than I) it is just confusing to you and the JVM about exactly which one you want to use at any given time. Fields are not overriden like methods are.
For all those things that are common, let the base class handle them. The constructor for your subclass should call the base class constructor (it does this anyway, but you should force it to call the "useful" constructor). After that, the sub class can do anything specific to itself:
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Constructor confusion...