Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialEgo Team
17,902 PointsPlease help! I get a runtime error. it seems like it doesn't like the Text node.
Here is my code!
package sample;
import javafx.application.Application; import javafx.fxml.FXMLLoader; import javafx.scene.Group; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.layout.VBox; import javafx.scene.text.Text; import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception{
//Parent proot = FXMLLoader.load(getClass().getResource("sample.fxml"));
Group root = new Group();
Text text = new Text("Sup?");
root.getChildren().add(text);
primaryStage.setTitle("Sup");
primaryStage.setScene(new Scene(root, 300, 275));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
And here is the error message i am getting.
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(Thread.java:745) Caused by: java.lang.NullPointerException at com.sun.t2k.MacFontFinder.initPSFontNameToPathMap(MacFontFinder.java:339) at com.sun.t2k.MacFontFinder.getFontNamesOfFontFamily(MacFontFinder.java:390) at com.sun.t2k.T2KFontFactory.getFontResource(T2KFontFactory.java:233) at com.sun.t2k.LogicalFont.getSlot0Resource(LogicalFont.java:184) at com.sun.t2k.LogicalFont.getSlotResource(LogicalFont.java:228) at com.sun.t2k.CompositeStrike.getStrikeSlot(CompositeStrike.java:86) at com.sun.t2k.CompositeStrike.getMetrics(CompositeStrike.java:132) at com.sun.javafx.font.PrismFontUtils.getFontMetrics(PrismFontUtils.java:31) at com.sun.javafx.font.PrismFontLoader.getFontMetrics(PrismFontLoader.java:466) at javafx.scene.text.Text.<init>(Text.java:153) at javafx.scene.text.Text.<init>(Text.java:162) at sample.Main.start(Main.java:24) at com.sun.javafx.application.LauncherImpl$5.run(LauncherImpl.java:319) at com.sun.javafx.application.PlatformImpl$5.run(PlatformImpl.java:219) at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:182) at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:179) at java.security.AccessController.doPrivileged(Native Method) at com.sun.javafx.application.PlatformImpl$4.run(PlatformImpl.java:179) at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:76)
Process finished with exit code 1
Please help!!!
2 Answers
Seth Kroger
56,413 PointsI did a little research on this and it looks like this is a bug specific to the Mac and Java 7 JDK. It's supposed to be fixed in the latest version of OpenJDK 7 (u95 or higher, the Oracle JDK ended public updates for 7), so I'd suggest updating your Java installation to that or a Java 8 SDK.
Bug details: https://bugs.openjdk.java.net/browse/JDK-8143907
Kyle Budd
7,821 PointsFor anyone that still may be experiencing this issue and doesn't want to update to SDK 8, stackoverflow offered an acceptable workaround. In the main method add the following:
try {
Class<?> macFontFinderClass = Class.forName("com.sun.t2k.MacFontFinder");
Field psNameToPathMap = macFontFinderClass.getDeclaredField("psNameToPathMap");
psNameToPathMap.setAccessible(true);
psNameToPathMap.set(null, new HashMap<String, String>());
} catch (Exception e) {
}