I'm trying to implement a singleton pattern for a System class. The examples I found do not compile (e.g. http://www.tutorialspoint.com/java/java_using_singleton.htm). There is a static method in a non-static class. So I made the class static and all was well until I tried to make a member variable for my Timer class.
Now I get the message "No enclosing instance of type scene_3d is accessible. Must qualify the allocation with an enclosing instance...
I have searched around but nobody's singleton patterns compile for me. By the way I am using Processing (a Java IDE/extension). Any ideas on how to fix this will be of great help. Thanks!
static public class DemoSystem {
private static DemoSystem instance = null;
protected DemoSystem() {}
public static DemoSystem Inst() {
if( instance == null ) {
instance = new DemoSystem();
}
return instance;
}
void init() {
Timer timer = new Timer();
}
int getTime() {
return timer.elapsedTime;
}
}