Skip to main content

Invoking a JavaFX Script

6 replies [Last post]
ramon_lopes
Offline
Joined: 2007-04-20
Points: 0

Hi folks,

I built a simple application, then I want run it outside my IDE, ie, by jar file.
I've found some materials, then I've tried this simple example:
http://jfx.wikia.com/wiki/Programmatically_invoking_a_JavaFX_Script

But when I run this application, it generates a NullPointerException!

I need help! It's so important to me!!!

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
megasween
Offline
Joined: 2007-11-25
Points: 0

If this is the line where the code is failing, I think you may have an issue with library files.

ScriptEngine engine = manager.getEngineByExtension("fx");

In my IDE this was happening when I forgot to include the JavaFXUserLib in the file. It was a result of the manager not having the needed script Engine.

agtorres
Offline
Joined: 2007-04-13
Points: 0

Thanks megasween, after browsing for several hours I was able to find this post with the solution.

baileysdeluxe
Offline
Joined: 2009-11-30
Points: 0

and whats the solution of ramon_lopes problem?? i have the same but i don´t know what the problem is. :-(

java.lang.NullPointerException
at java.io.Reader.(Reader.java:61)
at java.io.InputStreamReader.(InputStreamReader.java:55)

Message was edited by: baileysdeluxe

eoh
Offline
Joined: 2007-12-12
Points: 0

Which simple example ? There are some on that page. Please also post the stack trace.

ramon_lopes
Offline
Joined: 2007-04-20
Points: 0

Hi,

excuse me, I was so brief!
Here are the example:

Main.java

import java.io.InputStreamReader;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;

public class Main {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
try {
// set up script:
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByExtension("fx");
InputStreamReader reader =
new InputStreamReader(Main.class.getResourceAsStream("HelloWorld.fx"));
engine.eval(reader);

} catch (Exception e) {
e.printStackTrace();
}
}
}

HelloWorld.fx
import javafx.ui.*;
import javafx.ui.canvas.*;

Frame {
title: "Hello World!"
content: Label {
text: "Hello World with Java date"
}
visible: true

}

Output:
run:
java.lang.NullPointerException
at java.io.Reader.(Reader.java:61)
at java.io.InputStreamReader.(InputStreamReader.java:55)
at javaapplication5.Main.main(Main.java:18)
BUILD SUCCESSFUL (total time: 2 seconds)

this example is similar to site!
I don't know what is the problem. :(
Thanks,

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

The Main.java file should have 'package javaapplication5;' line and the HelloWorld.fx
file should be in the same package as Main.java file.