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 Java Basics Getting Started with Java Strings and Variables

error: cannot find symbol

input:

import java.io.Console;

public class Introductions {

    public static void main(String[] args) {
        Console console = System.console();
        // Welcome to the Introductions program!  Your code goes below here
        String.firstName = "Andrew";
        // thisIsInCamelCasing
        console.printf("Hello, my name is %s\n", firstName);
        console.printf("%s is learning java\n", firstName);
  }
}

output:

location: class Introductions
Introductions.java:11: error: cannot find symbol
console.printf("%s is learning java\n", firstName);
^
symbol: variable firstName
location: class Introductions
3 errors

edit:

also when doing the coding challenge to input a firstname i get

Input:

String.firstName = "Andrew";

Output:

JavaTester.java:73: error: cannot find symbol String.firstName = "Andy"; ^ symbol: variable firstName location: class String Note: JavaTester.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details. 1 error

3 Answers

michaelcodes
michaelcodes
5,604 Points

Hi there! The line of code that you have here:

String.firstName = "Andrew";

This line you are declaring a variable. For variable declaration you want to put a space between the type (String) and the name of the variable (firstName) as so:

String firstName = "Andrew";

The reason console.printf() uses a period is because it is a method being called from a class.

Hope this helps!

Manish Giri
Manish Giri
16,266 Points

This is wrong - String.firstName = "Andrew";

You have a . between String and firstName.

thanks all, syntax errors always get me