Anyone every used the singleton object successfully. I'm trying to create a Selenium object that I can access in different classes though out my project. I'm using the code below.

While I can declare the object everyplace and not get syntax errors. I get a error when I try to run any commands with the selenium object outside of the class where I start the server and open the browser.

public class Singleton {

// volatile is needed so that multiple thread can reconcile the instance
// semantics for volatile changed in Java 5.
private volatile static Singleton singleton;

private Selenium selenium;

public Selenium getSelenium(){
return selenium;
private Singleton() {

// synchronized keyword has been removed from here
public static Singleton getSingleton() {
// needed because once there is singleton available no need to acquire
// monitor again & again as it is costly
if(singleton==null) {
// this is needed if two threads are waiting at the monitor at the
// time when singleton was getting instantiated
if(singleton == null) {
try {
singleton = new Singleton();
singleton.selenium = (Selenium) new SeleniumServer();
} catch (Exception e) {
// TODO Auto-generated catch block

return singleton;