views:

85

answers:

2

I am developing in Eclipse a new Java project which uses an existing application (I have added its jar in my project build path). When I create an object of a class (say Model) from this existing application and use any of its methods,

Model model = new Model();
model.start();

I get the following error:

Exception in thread "main" java.lang.NullPointerException
at main.gui.mainwindow.MainWindow.run(MainWindow.java:56)
at main.gui.ApplicationController.main(ApplicationController.java:21)

When I create only the Model object (without calling its method), no error is given and my application works perfectly, does anyone know where the problme may lie? Thanks in advance!

+3  A: 

It sounds like there is an uninitialized value inside of your Model class and when you call start(), the class is trying to use the uninitialized value.

You might want to provide a concrete example rather than being Vague. You could be trying to use a class that has a dependency that you haven't set before trying to use some specific part of the class.

If Model (or whatever the real class may be) is something developed by somebody there, I would suggest asking them what could be going wrong or what you might be missing.

Justin Niessner
The first thing to do would be to look at line 56 of MainWindow.java to see what's there.
Paul Tomblin
@Paul Tomblin - I'm assuming that is where he was calling Model.start() or whatever the real code may be...hence asking what the real call looked like.
Justin Niessner
It appears that start() isn't even called.
Colin Hebert
It doesn't make sense that the error would be originating from line 56...he is creating a new instance of the class so the model variable is definitely not null. Like Justin said, the exception is probably being thrown from within the start() method.
Michael Angstadt
A: 

The oracle documentations says:

Thrown when an application attempts to use null in a case where an object is required. These include:

* Calling the instance method of a null object.
* Accessing or modifying the field of a null object.
* Taking the length of null as if it were an array.
* Accessing or modifying the slots of null as if it were an array.
* Throwing null as if it were a Throwable value. 

Applications should throw instances of this class to indicate other illegal uses of the null object.

Check if anything in here matches your case. It is impossible to say more without actually seeing the code.

inf.ig.sh
Oracle documentations -> NullPointerException javadocs
Timo Westkämper
Yeah? So whats wrong with the answear? It's from the oracle java documentations, this obvoius from the context.
inf.ig.sh