Допустим, у меня есть класс ресурсов, как это:JavaFX: Доступ в FXML к нестроковой-объекта из ResourceBundle
public class Resources extends java.util.ListResourceBundle {
private static final Object[][] OBJECTS = new Object[][]{
{"FOO", "foo"},
{"BAR", 123d}
}
@Override
protected Object[][] getContents() {
return OBJECTS;
}
}
В моем классе Application я загружаю fxml
так:
Resources resources = new Resources();
FXMLLoader loader = new FXMLLoader(getClass().getResource("/foo.fxml"), resources);
Parent root = loader.load();
в моей foo.fxml
я хочу использовать обе мои строки и мое двойное значение ресурса, например:
<Label text="%FOO">
<Polygon>
<points>
<Double fx:value="0"/>
<Double fx:value="0"/>
<Double fx:value="%BAR"/>
<Double fx:value="0"/>
</points>
</Polygon>
Первая линия работает отлично, но линия с fx:value="%BAR"
создает исключение следующим образом:
javafx.fxml.LoadException:
file:/foo.fxml:90
at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2579)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
at javafx.fxml.FXMLLoader.access$2700(FXMLLoader.java:103)
at javafx.fxml.FXMLLoader$IncludeElement.constructValue(FXMLLoader.java:1143)
at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:746)
at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2707)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2527)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2409)
at my Application class in line Parent root = loader.load();
at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NumberFormatException: For input string: "%BAR"
at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:2043)
at sun.misc.FloatingDecimal.parseDouble(FloatingDecimal.java:110)
at java.lang.Double.parseDouble(Double.java:538)
at java.lang.Double.valueOf(Double.java:502)
at com.sun.javafx.fxml.BeanAdapter.coerce(BeanAdapter.java:450)
at javafx.fxml.FXMLLoader$InstanceDeclarationElement.constructValue(FXMLLoader.java:982)
at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:746)
at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2707)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2527)
... 17 more
Так что мой вопрос: как использовать объекты ресурсов, кроме String
в FXML?
Редактировать: Еще проблема. Я даже попробовал {"BAR", new Double(123)}
в классе ресурсов. Появляется такая же ошибка, которая, честно говоря, имеет смысл, потому что это ничего, что логически фиксирует исключение. Я много думал об этом, и я очень потерялся здесь, так как я действительно хочу, чтобы это работало, и я понятия не имел, что делать. Спасибо за любую помощь!