Friday, April 3, 2015

Can't load an image to he background with Javafx


Revelant Code



Java Code:



package whowantstobeamillionairetriviagame;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

public class WhoWantsToBeAMillionaireTriviaGame extends Application
{
@Override
public void start(Stage startingStage)
{
StackPane root = new StackPane();
root.setId("MillionaireLogo");

Scene menuScene = new Scene(root, 1366, 768);
menuScene.getStylesheets().addAll(this.getClass().getResource("BackgroundImage.css").toExternalForm());
startingStage.setScene(menuScene);
startingStage.show();
}

public static void main(String[] args)
{
launch(args);
}
}

CSS File


Java Code:



#MillionaireLogo{
-fx-background-image: url("LOGO9.png");
-fx-background-size: 220 220;
-fx-background-position: center, center;
-fx-effect: dropshadow(three-pass-box, black, 30, 0.5, 0, 0);
}

Error that I'm getting

Exception in Application start method

java.lang.reflect.InvocationTargetException

at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:497)

at com.sun.javafx.application.LauncherImpl.launchAppl icationWithArgs(LauncherImpl.java:389)

at com.sun.javafx.application.LauncherImpl.launchAppl ication(LauncherImpl.java:328)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:497)

at sun.launcher.LauncherHelper$FXHelper.main(Launcher Helper.java:767)

Caused by: java.lang.RuntimeException: Exception in Application start method

at com.sun.javafx.application.LauncherImpl.launchAppl ication1(LauncherImpl.java:917)

at com.sun.javafx.application.LauncherImpl.lambda$lau nchApplication$152(LauncherImpl.java:182)

at com.sun.javafx.application.LauncherImpl$$Lambda$50/1642360923.run(Unknown Source)

at java.lang.Thread.run(Thread.java:745)

Caused by: java.lang.NullPointerException

at whowantstobeamillionairetriviagame.WhoWantsToBeAMi llionaireTriviaGame.start(WhoWantsToBeAMillionaire TriviaGame.java:17)

at com.sun.javafx.application.LauncherImpl.lambda$lau nchApplication1$159(LauncherImpl.java:863)

at com.sun.javafx.application.LauncherImpl$$Lambda$53/424011618.run(Unknown Source)

at com.sun.javafx.application.PlatformImpl.lambda$run AndWait$172(PlatformImpl.java:326)

at com.sun.javafx.application.PlatformImpl$$Lambda$46/355629945.run(Unknown Source)

at com.sun.javafx.application.PlatformImpl.lambda$nul l$170(PlatformImpl.java:295)

at com.sun.javafx.application.PlatformImpl$$Lambda$48/327580968.run(Unknown Source)

at java.security.AccessController.doPrivileged(Native Method)

at com.sun.javafx.application.PlatformImpl.lambda$run Later$171(PlatformImpl.java:294)

at com.sun.javafx.application.PlatformImpl$$Lambda$47/1915503092.run(Unknown Source)

at com.sun.glass.ui.InvokeLaterDispatcher$Future.run( InvokeLaterDispatcher.java:95)

at com.sun.glass.ui.win.WinApplication._runLoop(Nativ e Method)

at com.sun.glass.ui.win.WinApplication.lambda$null$14 5(WinApplication.java:101)

at com.sun.glass.ui.win.WinApplication$$Lambda$36/1963387170.run(Unknown Source)

... 1 more

Exception running application whowantstobeamillionairetriviagame.WhoWantsToBeAMi llionaireTriviaGame

Java Result: 1



No comments:

Post a Comment