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
Kae roe
341 PointsCan somebody please explain to me why this happens when I try to run anything
Cant find out why this is happening
2 Answers
miguelcastro2
Courses Plus Student 6,573 PointsBecause you are trying to build and run a Java class with code that is not at all Java. What you wrote is JSON, not Java.
Richard Ling
8,522 PointsYour file doesn't contain a class called index - you need to create something similar to the following:
import java.io.Console;
public class index {
public static void main(String[] args) {
Console console = System.console();
console.printf("Some nice family friendly text\n");
}
}
This is then compiled with
javac index.java
and executed with
java index
as you have done. When java index is run, the code inside the main method is executed. This creates a console object, and from that you can use the printf method to output to the screen.