B4J Question Error when opening fxml file

positrom2

Active Member
Licensed User
Longtime User
Frequently I cannot reopen an fxml file by the Scene builder.
This is the error message:
java.lang.ClassCastException: java.net.URL cannot be cast to java.lang.String
at com.oracle.javafx.authoring.watch.ProjectWatcher.toFileList(ProjectWatcher.java:745)
at com.oracle.javafx.authoring.watch.ProjectWatcher.access$600(ProjectWatcher.java:40)
at com.oracle.javafx.authoring.watch.ProjectWatcher$StyleSheetsHandler.retrieveSource(ProjectWatcher.java:350)
at com.oracle.javafx.authoring.watch.ProjectWatcher.retrievePropertyFiles(ProjectWatcher.java:385)
at com.oracle.javafx.authoring.watch.ProjectWatcher.visitElement(ProjectWatcher.java:631)
at com.oracle.javafx.authoring.watch.ProjectWatcher.init(ProjectWatcher.java:446)
at com.oracle.javafx.authoring.watch.ProjectWatcher.<init>(ProjectWatcher.java:434)
at com.oracle.javafx.authoring.Project.<init>(Project.java:586)
at com.oracle.javafx.authoring.Project.finish(Project.java:923)
at com.oracle.javafx.authoring.Project.forFxml(Project.java:839)
at com.oracle.javafx.authoring.Project.forFxml(Project.java:807)
at com.oracle.javafx.authoring.DesignerTool.loadFXMLLayout(DesignerTool.java:197)
at com.oracle.javafx.authoring.DesignerTool.loadFXMLLayout(DesignerTool.java:185)
at com.oracle.javafx.authoring.DesignerTool.commonInit(DesignerTool.java:513)
at com.oracle.javafx.authoring.DesignerTool.init(DesignerTool.java:457)
at com.oracle.javafx.authoring.SceneBuilderLauncher$RunningWithJMXInstance.launch(SceneBuilderLauncher.java:71)
at com.oracle.javafx.authoring.Main.start(Main.java:72)
at com.sun.javafx.application.LauncherImpl$5.run(LauncherImpl.java:319)
at com.sun.javafx.application.PlatformImpl$5.run(PlatformImpl.java:216)
at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:179)
at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:176)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl$4.run(PlatformImpl.java:176)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:76)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:17)
at com.sun.glass.ui.win.WinApplication$3$1.run(WinApplication.java:67)
at java.lang.Thread.run(Thread.java:724)
When I compare the file (using Winmerge) with a previous one that can be opened it is hard to see something offending (but the files are different since they are different version).
Any idea how to fix it?
 

Attachments

  • 2c_.zip
    1.1 KB · Views: 274
Last edited:

positrom2

Active Member
Licensed User
Longtime User
Update: It seems to very easy to produce a corrupt fxml file in Scene Builder just by "subtle" editing. I could not find out a reason.
The bad thing is as long as the Scene builder is open one can save the changes and they are well reproduced in the B4J screen, but when closing the Scene builder and reopening the edited fxml file I almost every time get the error
Loading the file '..fxml' has failed. Make sure it is a valid FXML File.
javanet.url cannot be cast to java.lang.String"
Opening the Details the message is as that posted in the first post.
It might reduce trouble not using the Scene Builder.
How to load the css file directly?
Or, how to put the style definitions string into the code?
 
Upvote 0

positrom2

Active Member
Licensed User
Longtime User
"Subtle" is hard to specify since I could not reopen the file to see what had been done....
But maybe this helps to explain what I did wrong within the Scene Builder:
An fxml file that can be opened and a successor file after a "minor" editing (just differing by an inserted css file as seen by an editor) that throws the error are attatched.
 

Attachments

  • fxmls_test.zip
    2.2 KB · Views: 263
Upvote 0

agraham

Expert
Licensed User
Longtime User
The problem is to do with the stylesheet elements.
B4X:
<stylesheets>
    <URL value="@2d.css" />
</stylesheets>
Remove these and it loads OK. It looks like quite a bad bug in SceneBuilder that lets it write files it cannot subsequently read. You didn't include the css files above so I have no idea how large they are. As a workaround could you put the entries directly in the Style box instead of in a Stylesheet?
 
Upvote 0

positrom2

Active Member
Licensed User
Longtime User
Here is the css file. (In the fxml file posted above i can see just the test.css file).
What is the style box?
But I think in view of this trouble it would indeed be better to load the styles directly. Could you post the lines how to do?
 

Attachments

  • test.zip
    465 bytes · Views: 246
Upvote 0

positrom2

Active Member
Licensed User
Longtime User
Last edited:
Upvote 0

positrom2

Active Member
Licensed User
Longtime User
Yes, a single line is no problem.
Would it be possible to load the caspian.css styles from the code?
I have attached a modified css file that is used by me in the SceneBuilder (to reduce the symbol sizes).
I was not able to build it as a string to be passed by SetStyle.

With the SceneBuilder I always have a bad feeling since I seem to have a lucky hand to produce an fxml file that can't be reloaded (cf. the previous posts).
I wonder that this does not seem to have been reported so far.
Placing the nodes seems to be safe. I would feel much better to apply the styles outside the SceneBuilder.
Also, that might be way for "hot" changing those styles, I mean when the app is running.
 

Attachments

  • test.zip
    468 bytes · Views: 269
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
In order to use selectors you need to load the css file. This is done by adding the CSS to the scene stylesheets list. Currently this method is not exposed. It will be exposed in the next update.

For now you can use JavaObject to access it:
B4X:
Dim jForm As JavaObject = MainForm
Dim scene As JavaObject = jForm.GetField("scene")
Dim stylesheets As List = scene.RunMethod("getStylesheets", Null)
stylesheets.Add(File.GetUri(File.DirAssets, "test.css"))
 
Upvote 0
Top