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

Define a string variable named firstName , illegal start of expression

Hello what i m doing wrong?

public class Name2 { public static void main(String[] args){
Console console = System.console();
String firstName= "Nick";
} }

Error Message :

JavaTester.java:56: error: illegal start of expression public class Name2 { ^

11 Answers

It worked when I added:
import java.io.Console;    
before:
public class Name2 {
Let me know if it works!!

we3 are on same stage nick lets work together

Stephen Bone
Stephen Bone
12,359 Points

Hi Nick & Admire

Does this query relate to the first coding challenge in Getting started with Java?

If so and the question is Define a string variable named firstName that stores your name. Set the value to your name.

Then yes all of the fancy class work has been taken care of (at this point) all you need is the string declaration as below:

String firstName = "Stephen";

Hope it helps!

Stephen

its giving me this error cannot find symbol string

Thanks for the answer but not working again! I try many things and i am so confused!

This is the code that works for me:

import java.io.Console;
public class Name2 { 
public static void main(String[] args) {
Console console = System.console();
String firstName = "Nick";
}}
Alexander Schott
Alexander Schott
8,318 Points

I can confirm that, if you include the proper package it will work.

I copy- paste you code and this happend in output.html.

JavaTester.java:52: error: illegal start of expression import java.io.Console; ^ JavaTester.java:52: error: not a statement import java.io.Console; ^ JavaTester.java:53: error: illegal start of expression public class Name2 { ^ 3 errors

Any answers ? i keep compile with erros and i can not find a solution.

Is this on a challenge?

If so, Craig might have already done:

import java.io.Console;
public class Name2 { 
public static void main(String[] args) {
Console console = System.console();

for you.

I am experiencing the same problem with nick help guys

Hello Admire i love team spirit lets do ti , here is my code and ISAIAH S , is there any difference from yours:

import java.io.Console; public class Name { public static void main(String[] args) { Console console = System.console(); String firstName = "Nick"; }}

And please telle me the erros in output.html

Yes, I have Name2 and you have Name.

No matters ISAIAH S the output for both of them(Name or Name2) are the same.Admire have you found something?

i did it just enter String firstName = "Nick"; as it is

i am on it havent succeded yet