2 Replies Latest reply on Oct 5, 2012 6:45 PM by shakir.gusaroff

    JavaFX 2.2 meet LAUNCH problem. Can anybody help ?

      I already download and use JDK 1.7 with JavaFX 2.2 version (Latest one at this time 2012/10/05).
      Download link is here ==>

      My Eclipse verioson is also the latest one on the web.
      Eclipse Java EE IDE for Web Developers.
      Version: Juno Release
      Build id: 20120614-1722

      Compile has passed, but bumped into error. Please see following trace dump. Why Javafx 2.0 has this error ?? How come ?
      Can anybody help me on this ??

      I search to the web and someone says that is a bug for JavaFX 2.0, but I use 2.2 instead? Dose this bug do not fix in 2.2 version ??

      I create a simple java application and cause the following run time error !!
      My platform is MS Windows 7 64-bit. I have installed "jdk-7u7-windows-x64.exe"
      Exception in Application start method
      Exception in thread "main" java.lang.RuntimeException: Exception in Application start method
      at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:403)
      at com.sun.javafx.application.LauncherImpl.access$000(LauncherImpl.java:47)
      at com.sun.javafx.application.LauncherImpl$1.run(LauncherImpl.java:115)
      at java.lang.Thread.run(Unknown Source)
      Caused by: java.lang.NullPointerException
      at com.engine.SpiderEngine$MyBrowser.<init>(SpiderEngine.java:55)
      at com.engine.SpiderEngine.start(SpiderEngine.java:39)
      at com.sun.javafx.application.LauncherImpl$5.run(LauncherImpl.java:319)
      at com.sun.javafx.application.PlatformImpl$5.run(PlatformImpl.java:206)
      at com.sun.javafx.application.PlatformImpl$4.run(PlatformImpl.java:173)
      at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
      at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:29)
      at com.sun.glass.ui.win.WinApplication$3$1.run(WinApplication.java:73)
      This code is simple copy from someone else and create a new project and paste into it.
      ALL COMPILING ISSUE is resolved, but with run time ERROR !!

      Meamwhile: How come HBox cannot pass error check for .addAll(TextField) ?? What I can do is simple mark them out !
      package com.engine;
      import java.awt.TextField;
      import java.net.URL;
      import javafx.application.Application;
      //import javafx.application.Platform;
      import javafx.event.ActionEvent;
      import javafx.event.EventHandler;
      import javafx.geometry.HPos;
      import javafx.geometry.Insets;
      import javafx.geometry.VPos;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.control.Label;
      import javafx.scene.layout.HBox;
      import javafx.scene.layout.Region;
      import javafx.scene.web.WebEngine;
      import javafx.scene.web.WebEvent;
      import javafx.scene.web.WebView;
      import javafx.stage.Stage;
      public class SpiderEngine extends Application
           public static void main(String[] args)
                // TODO Auto-generated method stub
           private Scene scene;
           MyBrowser myBrowser;
           public void start(Stage primaryStage)
                myBrowser = new MyBrowser();
                scene = new Scene(myBrowser, 640, 480);
           class MyBrowser extends Region
                HBox toolbar;
                WebView webView = new WebView();
                WebEngine webEngine = webView.getEngine();
                public MyBrowser()
                     final Label labelWebTitle = new Label();
                     final URL urlHello = getClass().getResource("hello.html");
                     webEngine.setOnAlert(new EventHandler<WebEvent<String>>(){
                          public void handle(WebEvent<String> arg0) {
                     final TextField textField = new TextField ();
                     textField.setText("Hello! Who are?");
                     Button buttonEnter = new Button("Enter");
                     buttonEnter.setOnAction(new EventHandler<ActionEvent>(){
                          public void handle(ActionEvent arg0)
                               webEngine.executeScript( " updateHello(' " + textField.getText() + " ') " );
                     Button buttonClear = new Button("Clear");
                     buttonClear.setOnAction(new EventHandler<ActionEvent>(){
                          public void handle(ActionEvent arg0)
                               webEngine.executeScript( "clearHello()" );
                     toolbar = new HBox();
                     toolbar.setPadding(new Insets(10, 10, 10, 10));
                     toolbar.setStyle("-fx-background-color: #336699");
                     //toolbar.getChildren().add(textField);    // <==  THIS LINE CANNOT PASS COMPILER !!
                protected void layoutChildren()
                     double w = getWidth();
                     double h = getHeight();
                     double toolbarHeight = toolbar.prefHeight(w);
                     layoutInArea(webView, 0, 0, w, h-toolbarHeight, 0, HPos.CENTER, VPos.CENTER);
                     layoutInArea(toolbar, 0, h-toolbarHeight, w, toolbarHeight, 0, HPos.CENTER, VPos.CENTER);
      Edited by: 963448 on 2012/10/5 上午 8:41
        • 1. Re: JavaFX 2.2 meet LAUNCH problem. Can anybody help ?
          As jsmith already pointed out, this is caused by a NullPointerException at line 55, meaning that something on line 55 has not been properly initialized.

          Line 55 is
          so the two candidates for uninitialized references are webEngine and urlHello.

          WebEngine is initialized as webView.getEngine(), which should be fine. urlHello is initialized with getClass().getResource("hello.html").

          If you look at the javadocs for getResource (in java.lang.Class), they explicitly state

          A URL object or null if no resource with this name is found

          So the resource "hello.html" probably can't be found. Check that it exists and is in the correct location.

          For the toolbar.getChildren().add(textField), the problem is the type of the textField. The add method is expecting a Node. You have imported java.awt.TextField, which is not a Node; you need to import javafx.scene.control.TextField instead.
          • 2. Re: JavaFX 2.2 meet LAUNCH problem. Can anybody help ?
            Hi. The url of your html file is:
            final URL urlHello = getClass().getResource("hello.html");
            Your java class and the hello.html file should be in the same place. Your project structure
            should be like this:
                      -  SpiderEngine.java
                      -  hello.html   
            Also replace java.awt.TextField with javafx.scene.control.TextField;