Reputation: 4305
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!
Upvotes: 1
Views: 717
Reputation: 1627
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.
Upvotes: -1
Reputation: 245509
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.
Upvotes: 3