Skip to main content

Use of Singleton-implementation

5 replies [Last post]
are
Offline
Joined: 2008-05-13
Points: 0

Hello,

inside a JavaFX class i'd like to use a plain JAVA class that implements the Singleton-pattern.

function test():Void {
var settings=Settings.getInstance();
datasource=settings.get("jPortfolioView","file","datasource");
}

Settings is the existing and working Java-class. datasource is an attribute of my JavaFX-class. However, there will be errors:

/home/are/src/jPortfolioView/src/PortfolioView/SettingsFrame.fx:327: non-static variable datasource cannot be referenced from a static context
var settings=Settings.getInstance();
1 error

I don't understand these message. With the JavaFX Script Interpreter it worked so well :(

Best regards
are

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
alexsch
Offline
Joined: 2007-07-12
Points: 0

How do you define [b]datasource[/b] variable?

are
Offline
Joined: 2008-05-13
Points: 0

attribute datasource:String;

it's an attribute of the JavaFx class.

Best regards
are

alexsch
Offline
Joined: 2007-07-12
Points: 0

The following code is compiled on my side:

[code]
// ------------ Settings.java -----------------------------
public class Settings {
public static Settings getInstance(){ return new Settings(); }
public String get(String s1, String s2, String s3) {return ""; }
}

// ------------ Test.fx ---------------------------------------------
class JavaFx {

public attribute datasource:String;

function test():Void {
var settings=Settings.getInstance();
datasource = settings.get("jPortfolioView","file","datasource");
}

}
[/code]

Is it different from your code?

are
Offline
Joined: 2008-05-13
Points: 0

Thank for ypur kinde assistance!

Unfortunately the code looks similar. Are you using the netbeans plugin or the compiler package? How ever, with your line I can hunt this beast down line by line as I know that your line work.

Best regards
are

alexsch
Offline
Joined: 2007-07-12
Points: 0

I use JavaFX Script Plugin for NetBeans IDE 6.1:
http://javafx.netbeans.org/download-compiler-JFXplugin.html