Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Exception in Application start method

user8709910Jun 7 2013 — edited Jun 7 2013
Dear Friends,


I am trying to develop javafx programs, here is an unknown exception I got:


ant -f C:\\Users\\haris\\Documents\\NetBeansProjects\\fxlogin jfxsa-run
init:
Deleting: C:\Users\haris\Documents\NetBeansProjects\fxlogin\build\built-jar.properties
deps-jar:
Updating property file: C:\Users\haris\Documents\NetBeansProjects\fxlogin\build\built-jar.properties
compile:
Detected JavaFX Ant API version 1.2
jfx-deployment:
jar:
Copying 12 files to C:\Users\haris\Documents\NetBeansProjects\fxlogin\dist\run993276176
jfx-project-run:
Executing com.javafx.main.Main from C:\Users\haris\Documents\NetBeansProjects\fxlogin\dist\run993276176\fxlogin.jar using platform C:\Program Files\Java\jdk1.7.0_21/bin/java
Exception in Application start method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.javafx.main.Main.launchApp(Main.java:642)
at com.javafx.main.Main.main(Main.java:805)
Caused by: 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(Thread.java:722)
Caused by: java.lang.NullPointerException
at fxlogin.Fxlogin.start(Fxlogin.java:70)
at com.sun.javafx.application.LauncherImpl$5.run(LauncherImpl.java:319)
at com.sun.javafx.application.PlatformImpl$5.run(PlatformImpl.java:215)
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.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)
... 1 more
Java Result: 1
Deleting directory C:\Users\haris\Documents\NetBeansProjects\fxlogin\dist\run993276176
jfxsa-run:
BUILD SUCCESSFUL (total time: 9 seconds)



here is my code

/*
Document : Login
Created on : Jun 7, 2013, 11:11:36 PM
Author : haris
Description:
Purpose of the stylesheet follows.
*/

.root {
display: block;
-fx-background-image: url("background.jpg");

}

java class

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package fxlogin;

import javafx.scene.control.Button;
import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import javafx.stage.Stage;
import javafx.scene.layout.GridPane ;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.geometry.Insets;
import javafx.scene.layout.HBox;
/**
*
* @author haris
*/




public class Fxlogin extends Application {

@Override
public void start(Stage primaryStage) {


primaryStage.setTitle("JavaFX Welcome");

GridPane grid = new GridPane();
grid.setAlignment(Pos.CENTER);
grid.setHgap(10);
grid.setVgap(10);
grid.setPadding(new Insets(25, 25, 25, 25));

Text scenetitle = new Text("Welcome");
scenetitle.setFont(Font.font("Tahoma", FontWeight.NORMAL, 20));
grid.add(scenetitle, 0, 0, 2, 1);

Label userName = new Label("User Name:");
grid.add(userName, 0, 1);

TextField userTextField = new TextField();
grid.add(userTextField, 1, 1);

Label pw = new Label("Password:");
grid.add(pw, 0, 2);

PasswordField pwBox = new PasswordField();
grid.add(pwBox, 1, 2);

Button btn = new Button("Sign in");
HBox hbBtn = new HBox(10);
hbBtn.setAlignment(Pos.BOTTOM_RIGHT);
hbBtn.getChildren().add(btn);
grid.add(hbBtn, 1, 4);
final Text actiontarget = new Text();
grid.add(actiontarget, 1, 6);


Scene scene = new Scene(grid, 300, 275);
primaryStage.setScene(scene);
scene.getStylesheets().add(Fxlogin.class.getResource("Login.css").toExternalForm());
primaryStage.show();
}

/**
* The main() method is ignored in correctly deployed JavaFX application.
* main() serves only as fallback in case the application can not be
* launched through deployment artifacts, e.g., in IDEs with limited FX
* support. NetBeans ignores main().
*
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}


Why do I get this exception??? thank you

Edited by: user8709910 on Jun 7, 2013 1:45 PM

Comments

jsmith
It is not an unknown exception, the stack trace tells you that it is a NullPointerException.
http://docs.oracle.com/javase/7/docs/api/java/lang/NullPointerException.html

What is the code at line 70 of FxLogin.java?
fxlogin.Fxlogin.start(Fxlogin.java:70)

Whatever that line is, it is causing a NullPointerException:
http://stackoverflow.com/questions/218384/what-is-a-null-pointer-exception

Please use code formatting tags when pasting code:
https://forums.oracle.com/forums/ann.jspa?annID=1622
user8709910
The actual process is to add css file in the project like instructing here: http://docs.oracle.com/javafx/2/get_started/css.htm

but even if follow the steps the exception is thrown, seems that the class cannot find the css file. Where do I have to put the css file?
shakir.gusaroff
It works for me. Your project structure should be:
Fxlogin
	Source packages
		fxlogin
			Fxlogin.java
			Login.css
			background.jpg
1 - 3
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Jul 5 2013
Added on Jun 7 2013
3 comments
9,834 views