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 trialMojo Waters
5,748 Pointsit says that prepareAttempt in Home.java cannot be applied to (boolean).
Guys:
This line is not working mTimeLine.setOnFinished(e -> { prepareAttempt(mCurrentAttempt.getKind() == AttemptKind.FOCUS) ? AttemptKind.BREAK : AttemptKind.FOCUS; }); } It says that prepareAttempt cannot be applied to boolean. Where did boolean come from?
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.layout.VBox; import javafx.util.Duration;
public class Home {
@FXML
private VBox container;
@FXML
private Label title;
private Attempt mCurrentAttempt;
private StringProperty mTimerText;
private Timeline mTimeLine;
public Home() {
mTimerText = new SimpleStringProperty();
setTimerText(0);
}
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:%02d",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 -> {
prepareAttempt(mCurrentAttempt.getKind() == AttemptKind.FOCUS) ?
AttemptKind.BREAK : AttemptKind.FOCUS;
});
}
private void reset() {
clearAttemptStyles();
if(mTimeLine != null && mTimeLine.getStatus() == Animation.Status.RUNNING) {
mTimeLine.stop();
}
}
public void playTime() {
mTimeLine.play();
}
public void pauseTime() {
mTimeLine.pause();
}
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("Hey Mom");
}
public void handleRestart(ActionEvent actionEvent) {
prepareAttempt(AttemptKind.FOCUS);
playTime();
}
}
2 Answers
Matthew Hardy
4,063 PointsI believe this has to do with how your parentheses are lined up.
mTimeLine.setOnFinished(e -> { prepareAttempt ( mCurrentAttempt.getKind () == AttemptKind.FOCUS ) ? AttemptKind.BREAK : AttemptKind.FOCUS; });
The way these two (bolded above) are set up mean you are calling prepareAttempt on "mCurrentAttempt.getKind () == AttemptKind.FOCUS" which in itself returns a boolean value. You should reorder you parentheses to
mTimeLine.setOnFinished(e -> { prepareAttempt(mCurrentAttempt.getKind () == AttemptKind.FOCUS ? AttemptKind.BREAK : AttemptKind.FOCUS)});
so that AttemptKind.FOCUS ? AttemptKind.BREAK : AttemptKind.FOCUS can actually decipher which mode you are in
Mojo Waters
5,748 PointsHi Matthew,
Thank you for your help. Yes, it was in parentheses. It's all fixed now.
Have a great day and thanks again
Kind regards Mojo