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 trial

Java Build a JavaFX Application Build a Pomodoro App Build the State Change Events

can't import class, error in home.fxml

<Label fx:id="title" text="Pomodoro"/>

it's giving me an error and "title" is red. in the video, he changes his class to javafx.scene... but i'm not getting that option, and it's the only thing hanging me up from being able to run the code!

Mike Papamichail
Mike Papamichail
4,883 Points

What's the error you're getting? :D

Home.fxml: <?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.?> <?import javafx.scene.image.Image?> <?import javafx.scene.image.ImageView?> <?import javafx.scene.layout.?> <?import javafx.scene.shape.SVGPath?> <VBox stylesheets="/css/main.css" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml" fx:controller="com.teamtreehouse.pomodoro.controllers.Home" fx:id="container"> <children> <Button fx:id="DEBUG" onAction="#DEBUG">DEBUG</Button>

    <Label fx:id="title" text="Pomodoro"/>

    <Label fx:id="time" text="${controller.timerText}"/>

    <HBox styleClass="buttons">
        <children>
            <StackPane>
                <children>
                    <StackPane styleClass="nested-action,play">
                        <children>
                            <HBox styleClass="svg-container">
                                <SVGPath styleClass="svg"
                                         content="M1.6 17C1 17 0 16.2 0 15.6V1.3C0 .1 2.2-.4 3.1.4l8.2 6.4c.5.4.8 1 .8 1.7 0 .6-.3 1.2-.8 1.7l-8.2 6.4c-.5.2-1 .4-1.5.4z"/>
                            </HBox>
                            <Button text="Resume"/>
                        </children>
                    </StackPane>

                    <StackPane styleClass="nested-action,pause">
                        <children>
                            <HBox styleClass="svg-container">
                                <SVGPath styleClass="svg"
                                         content="M10.2 17c-1 0-1.8-.8-1.8-1.8V1.8c0-1 .8-1.8 1.8-1.8S12 .8 12 1.8v13.4c0 1-.8 1.8-1.8 1.8z" />
                                <SVGPath styleClass="svg"
                                         content="M10.2 17c-1 0-1.8-.8-1.8-1.8V1.8c0-1 .8-1.8 1.8-1.8S12 .8 12 1.8v13.4c0 1-.8 1.8-1.8 1.8z" />
                            </HBox>
                            <Button text="Pause"/>
                        </children>
                    </StackPane>
                </children>
            </StackPane>

            <StackPane styleClass="nested-action,restart">
                <children>
                    <HBox styleClass="svg-container">
                        <SVGPath styleClass="svg"
                                 content="M21 2.9C19.1 1 16.6 0 13.9 0c-1.1 0-2 .9-2 1.9s.9 1.9 2 1.9c1.7 0 3.2.6 4.4 1.8 2.4 2.4 2.4 6.3 0 8.7-1.2 1.2-2.7 1.8-4.4 1.8-1.7 0-3.2-.6-4.4-1.8-1.8-1.8-2.3-4.4-1.4-6.7L9.3 10c.2.4.5.7.9.8.4.1.8.1 1.2-.1.8-.4 1.1-1.3.8-2.1L10 4.3c0-.5-.2-1-.6-1.4l-.1-.1-.1-.2c-.2-.4-.5-.7-.9-.8-.4-.1-.8-.1-1.2.1L.9 4.8C.1 5.2-.2 6.1.2 6.9c.2.4.5.7.9.8.4.1.8.1 1.2-.1l2-.9c-1.2 3.5-.4 7.6 2.4 10.4C8.6 19 11.2 20 13.9 20s5.3-1 7.2-2.9C25 13.2 25 6.8 21 2.9z"/>
                    </HBox>
                    <Button text="Restart"/>
                </children>
            </StackPane>
        </children>
    </HBox>

    <TextArea fx:id="message" promptText="What are you doing?"/>

    <ImageView>
        <image>
            <Image url="/images/pomodoro.png"/>
        </image>
    </ImageView>

</children>

</VBox>

Home.java:

package com.teamtreehouse.pomodoro.controllers;

import com.teamtreehouse.pomodoro.model.Attempt; import com.teamtreehouse.pomodoro.model.AttemptKind; import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.scene.layout.VBox;

import java.awt.*;

public class Home { @FXML private VBox container;

@FXML private Label title;

private Attempt mCurrentAttempt;
private StringProperty mTimerText;

public Home () {
    mTimerText = new SimpleStringProperty();
    setTimerText(0);

}

public String getTimerText() {
    return mTimerText.get();
}

public StringProperty timerTextProperty() {
    return mTimerText;
}

public void setTimerText(String timerText) {
    this.mTimerText.set(timerText);
}

public void setTimerText(int remainingSeconds){
    int minutes = remainingSeconds / 60;
    int seconds = remainingSeconds % 60;
    setTimerText(String.format("%02d:%02d", minutes, seconds));
}

private  void prepareAttempt(AttemptKind kind) {
    clearAttemptStyles();
    mCurrentAttempt = new Attempt(kind, "");
    addAttemptStyle(kind);
    title.setText(kind.getDisplayName());
    setTimerText(mCurrentAttempt.getRemaingSeconds());
}

private void addAttemptStyle(AttemptKind kind) {
    container.getStyleClass().add(kind.toString().toLowerCase());
}

private void clearAttemptStyles()  {
    for (AttemptKind kind : AttemptKind.values()) {
        container.getStyleClass().remove(kind.toString().toLowerCase());
    }

}

public void DEBUG(ActionEvent actionEvent) {
    System.out.println("HI MOM");
}

}

Errors:

"C:\Program Files\Java\jdk1.8.0_151\bin\java" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2017.2.6\lib\idea_rt.jar=59886:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2017.2.6\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_151\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_151\jre\lib\rt.jar;C:\Users\Sony_User\Desktop\TeamTreeHouse\pomodoro-project\project\s3v1\out\production\Pomodoro" com.teamtreehouse.pomodoro.Main Exception in Application start method java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389) at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767) Caused by: java.lang.RuntimeException: Exception in Application start method at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917) at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$154(LauncherImpl.java:182) at java.lang.Thread.run(Thread.java:748) Caused by: javafx.fxml.LoadException: /C:/Users/Sony_User/Desktop/TeamTreeHouse/pomodoro-project/project/s3v1/out/production/Pomodoro/fxml/home.fxml:16

at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2579)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3214)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3104)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097)
at com.teamtreehouse.pomodoro.Main.start(Main.java:16)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
... 1 more

Caused by: java.lang.IllegalArgumentException: Can not set java.awt.Label field com.teamtreehouse.pomodoro.controllers.Home.title to javafx.scene.control.Label at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:167) at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:171) at sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:81) at java.lang.reflect.Field.set(Field.java:764) at javafx.fxml.FXMLLoader.injectFields(FXMLLoader.java:1163) at javafx.fxml.FXMLLoader.access$1600(FXMLLoader.java:103) at javafx.fxml.FXMLLoader$ValueElement.processValue(FXMLLoader.java:857) at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:751) at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2707) at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2527) ... 17 more Exception running application com.teamtreehouse.pomodoro.Main

Process finished with exit code 1

1 Answer

I went back in with fresh eyes and fixed it! sorry for your trouble! side note I'm over 9 months pregnant on maternity leave trying to learn to code in between contractions, so my mind is not as clear as I'd like it to be! lolol