Sponsored Link •
|
Advertisement
|
Advertisement
|
This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.
Message:
Sorry about the previous post, I accidently hit "post" half way through... I'm trying to implement a class that uses a static method to return an instance of itself to the calling object. It's not precisely a singleton because it can also be instantiated via a call to a constructor. I've gotten it to work more or less correctly, but I'm having trouble with methods in the instance that access non-static variables: The pertinent code follows: public class GeneManager { private GeneManagerGUI gui; private static GeneManager manager;
public void setGUI(GeneManagerGUI gui) { public static GeneManager getGeneManager() {
From an object that doesn't have a reference to the GeneManager, I call getGeneManager to get reference to the one instance of the GeneManager. Later on, I use that instance to create a GeneMangerGUI display of the Manager (represented by the non-static variable gui above), which calls setGUI in the manager, giving GeneManager a reference to the Gui that displays its information. However, when I call any methods in the GeneManager that reference the instance of gui, I get a NullPointerException. For example: A call to... public void newGroup(String sourceName) { throws a NullPointerException when gui.selectNewEntry is called. I would really appreciate any help that anyone can give. I'm a bit unfamiliar with static methods and variables, and hope someone can give me a hand. Thanks, Tim
Replies:
|
Sponsored Links
|