Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Java Build a JavaFX Application Design a Better App Grids

Why " Label label = new Label("Name:"); " doesn't work?

Hello,

I was wondering why when I type the line of code to create a new Label in my JavaFx project it doesn't work and gives the error message of " Label() cannot be applied to '(java.lang.String)' "

Label label = new Label("Name:");

After some quick trials, I figured that this works instead,
javafx.scene.control.Label label = new javafx.scene.control.Label("Name:");

As a newbie, I'm clueless why? Is there something wrong with my Intellij' settings?

1 Answer

Alexander Nikiforov
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Alexander Nikiforov
Java Web Development Techdegree Graduate 22,162 Points

Check import statement.

Up top in file should be

import javafx.scene.control.Label;

You've probably imported wrong label. The one that does not have constructor with String