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

Cannot finalize the app. Need some help. I did everything as per the course but cannot still get errors. Thanks heaps

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:917)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$155(LauncherImpl.java:182)
    at java.lang.Thread.run(Thread.java:745)
Caused by: javafx.fxml.LoadException: 
/Users/jonathanhecator/Documents/IdeaProjects/Pomodoro/out/production/Pomodoro/fxml/home.fxml:12

    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:15)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
    at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
    at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
Caused by: java.util.FormatFlagsConversionMismatchException: Conversion = s, Flags = 0
    at java.util.Formatter$FormatSpecifier.failMismatch(Formatter.java:4298)
    at java.util.Formatter$FormatSpecifier.checkBadFlags(Formatter.java:2997)
    at java.util.Formatter$FormatSpecifier.checkGeneral(Formatter.java:2955)
    at java.util.Formatter$FormatSpecifier.<init>(Formatter.java:2725)
    at java.util.Formatter.parse(Formatter.java:2560)
    at java.util.Formatter.format(Formatter.java:2501)
    at java.util.Formatter.format(Formatter.java:2455)
    at java.lang.String.format(String.java:2940)
    at com.teamtreehouse.pomodoro.controllers.Home.setTimerText(Home.java:58)
    at com.teamtreehouse.pomodoro.controllers.Home.<init>(Home.java:39)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at java.lang.Class.newInstance(Class.java:442)
    at sun.reflect.misc.ReflectUtil.newInstance(ReflectUtil.java:51)
    at javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:927)
    at javafx.fxml.FXMLLoader$InstanceDeclarationElement.processAttribute(FXMLLoader.java:971)
    at javafx.fxml.FXMLLoader$Element.processStartElement(FXMLLoader.java:220)
    at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:744)
    at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2707)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2527)
    ... 14 more

Process finished with exit code 1


```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>

        <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>


```java
package com.teamtreehouse.pomodoro.controllers;

import com.teamtreehouse.pomodoro.model.Attempt;
import com.teamtreehouse.pomodoro.model.AttemptKind;
import javafx.animation.Animation;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.layout.VBox;
import javafx.scene.media.AudioClip;
import javafx.util.Duration;


/**
 * @author jonathanhector on 13.02.17.
 */
public class Home {
    private final AudioClip mApplause;
    @FXML
    private VBox container;

    @FXML
    private Label title;

    @FXML
    private TextArea message;

    private Attempt mCurrentAttempt;
    private StringProperty mTimerText;
    private Timeline mTimeline;

    public Home() {
        mTimerText = new SimpleStringProperty();
        setTimerText(0);
        mApplause = new AudioClip(getClass().getResource("/sound/applause.mp3").toExternalForm());
    }

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

    public StringProperty timerTextProperty() {
        return mTimerText;
    }

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

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

    private void prepareAttempt(AttemptKind kind) {
        reset();
        mCurrentAttempt = new Attempt(kind, "");
        addAttemptStyle(kind);
        title.setText(kind.getDisplayName());
        setTimerText(mCurrentAttempt.getRemainingSeconds());
        mTimeline = new Timeline();
        mTimeline.setCycleCount(kind.getTotalSeconds());
        mTimeline.getKeyFrames().add(new KeyFrame(Duration.seconds(1), e -> {
            mCurrentAttempt.tick();
            setTimerText(mCurrentAttempt.getRemainingSeconds());
        }));
        mTimeline.setOnFinished(e -> {
            saveCurrentAttempt();
            mApplause.play();
            prepareAttempt(mCurrentAttempt.getKind() == AttemptKind.FOCUS ? AttemptKind.BREAK : AttemptKind.FOCUS);
        });
    }

    private void saveCurrentAttempt() {
        mCurrentAttempt.setMessage(message.getText());
        mCurrentAttempt.save();
    }

    private void reset() {
        if(mTimeline != null && mTimeline.getStatus() == Animation.Status.RUNNING) {
            mTimeline.stop();
        }
    }

    private void playTimer() {
        container.getStyleClass().add("playing");
        mTimeline.play();
    }

    private void pauseTimer() {
        container.getStyleClass().remove("playing");
        mTimeline.pause();
    }

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

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

    @FXML
    public void DEBUG(ActionEvent actionEvent) {
        System.out.println("Hello");
    }

    @FXML
    public void handleRestart(ActionEvent actionEvent) {
        prepareAttempt(AttemptKind.FOCUS);
        playTimer();
    }

    @FXML
    public void handlePause(ActionEvent actionEvent) {
        pauseTimer();
    }


    @FXML
    public void handlePlay(ActionEvent actionEvent) {
        if (mCurrentAttempt == null){
            handleRestart(actionEvent);
        } else {
            playTimer();
        }
    }
}


```java
package com.teamtreehouse.pomodoro.model;

/**
 * @author jonathanhector on 09.01.17.
 */
public enum AttemptKind {
    FOCUS(25 * 60, "Focus Time"),
    BREAK(5 * 60, "Break Time");

    private int mTotalSeconds;
    private String mDisplayName;

    AttemptKind(int totalSeconds, String displayName){
        mTotalSeconds = totalSeconds;
        mDisplayName = displayName;
    }

    public int getTotalSeconds(){
        return mTotalSeconds;
    }

    public String getDisplayName() {
        return mDisplayName;
    }
}


```java
package com.teamtreehouse.pomodoro;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.text.Font;
import javafx.stage.Stage;

public class Main extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception{
        Font.loadFont(getClass().getResource("/fonts/VarelaRound-Regular.ttf").toExternalForm(), 10);
        Parent root = FXMLLoader.load(getClass().getResource("/fxml/home.fxml"));
        primaryStage.setTitle("Pomodoro Timer");
        primaryStage.setScene(new Scene(root, 500, 500));
        primaryStage.setFullScreen(true);
        primaryStage.setResizable(true);
        primaryStage.show();
    }


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

```css
* {
    -fx-font-family: 'Varela Round';
    -fx-alignment: center;
    -fx-text-fill: #fff;
}

#container {
    -fx-background: #35B55C;
    -fx-pref-width: 500px;
    -fx-padding: 75px;
    -fx-spacing: 20px;
}


#title {
    -fx-font-size: 31px;
}

#time {
    -fx-content-display: center;
    -fx-pref-width: 350px;
    -fx-background-color: #202428;
    -fx-font-size: 72px;
    -fx-line-height: 80px;
    -fx-border-radius: 8px;
    -fx-letter-spacing: 10px;
}

.buttons {
    -fx-spacing: 10px;
}

.button {
  -fx-border-radius: 6px;
  -fx-border-width: 2px;
  -fx-border-style: solid;
  -fx-border-color: #fff;
  -fx-background-color: none;
  -fx-text-fill: #fff;
  -fx-fill-width: true;
  -fx-cursor: pointer;
  -fx-padding: 10px 10px 10px 37px;
  -fx-font-size: 20px;

}

.nested-action {
    -fx-padding: 0px;
}

.svg-container {
    -fx-padding: 0 0 0 17px;
    -fx-alignment: center-left;
}


.restart .button {
    -fx-padding: 10px 10px 10px 43px;
}

.svg {
    -fx-fill: #fff;
    -fx-height: 15px;
}


.text-area {
    -fx-pref-width: 300px;
    -fx-pref-row-count: 3;
    -fx-border-radius: 6px;
    -fx-border-width: 2px;
    -fx-border-color: #fff;
    -fx-border-style: solid;
    -fx-font-size: 20px;
    -fx-text-fill: #000;
}

/* State based selectors */

.pause .svg-container {
    -fx-padding: 0 0 0 25px;
    -fx-spacing: 5px;
}

.pause {
    visibility: hidden;
}

.playing .pause {
    visibility: visible;
}

.playing .play {
    visibility: hidden;
}

.focus {
    -fx-background-color: #2D3339;
}

.break {
    -fx-background-color: #3F8ABF;;
}

#pomodoro {
    -fx-fit-height: 34px;
}

3 Answers

I don't know how you named your folders but my folder for the sounds is called "sounds". In your Home controller constructor you have this line:

mApplause = new AudioClip(getClass().getResource("/sound/applause.mp3").toExternalForm());

If your folder is named like mine you have to change "sound" to "sounds". It cannot find the folder and is therefore null.

Keep it coming ;-)

Kind Regards, Florian

Hi Jonathan,

in the setTimerText() method in your Home class change

        setTimerText(String.format("%02d:%02s", minutes, seconds));

to

        setTimerText(String.format("%02d:%02d", minutes, seconds));

You are using the "%02" conversion flags on a String, you can only use those on a number.

Kind Regards, Florian

thanks heaps Florian. I've tried that and I still get the following errors. Thanks for your help in advance.

/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/bin/java ...
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:917)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$155(LauncherImpl.java:182)
    at java.lang.Thread.run(Thread.java:745)
Caused by: javafx.fxml.LoadException: 
/Users/jonathanhecator/Documents/IdeaProjects/Pomodoro/out/production/Pomodoro/fxml/home.fxml:12

    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:15)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
    at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
    at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
Caused by: java.lang.NullPointerException
    at com.teamtreehouse.pomodoro.controllers.Home.<init>(Home.java:40)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at java.lang.Class.newInstance(Class.java:442)
    at sun.reflect.misc.ReflectUtil.newInstance(ReflectUtil.java:51)
    at javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:927)
    at javafx.fxml.FXMLLoader$InstanceDeclarationElement.processAttribute(FXMLLoader.java:971)
    at javafx.fxml.FXMLLoader$Element.processStartElement(FXMLLoader.java:220)
    at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:744)
    at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2707)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2527)
    ... 14 more

Thanks. You reckon that you could double check my fxml file. I think it's coming from there but I can't figure out from where. Your help is really appreciated