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
Charlie Flowers
612 PointsWhy does this code not work?
In workspaces I ran this code and it works fine.
import java.io.Console;
public class Introductions {
public static void main(String[] args) {
Console console = System.console();
String firstName = "awesome and epic";
console.printf("I am %s.\n", firstName);
console.printf("I am more %s than you think\n", firstName);
} }
Then a question asked to run a program that has a string. I did that but it said that there were syntax errors so it couldn't run. These were the errors.
JavaTester.java:73: error: illegal start of expression import java.io.Console; ^ JavaTester.java:73: error: not a statement import java.io.Console; ^ JavaTester.java:75: error: illegal start of expression public class Introductions { ^
What did I do wrong and how should I fix it?
Thanks
Andrew Trachtman
3,680 PointsI don't know where you're running this code (I'm assuming not in workspaces), but it could be that you need to add a package based on your folder structure. For example, in NetBeans you might have made a project: MyProject.
That project would contain a Source Packages folder and a myproject package. Every Java file in the package should specify the package it is contained in. Based on the folder structure of Workspaces, I don't think it looks for any of that.
package myproject;
import java.io.Console;
public static void main(String[] args){
}
Whatever you're running on might be looking for that package declaration before anything else, but I don't know for sure.
jcr
18,523 Pointsjcr
18,523 PointsCharlie, did you include here the code that you ran that didn't work or just the code that worked? I entered the above code into workspaces and it runs fine. If there is additional code, please add that.