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
Matthew McGeehan
995 PointsUsing an outside IDE in Java???
Hello All,
I tried running the following code in Dr. Java:
import java.io.Console;
public class TreeStory {
public static void main(String[] args) {
Console console = System.console();
/* Some terms:
noun - Person, place or thing
verb - An action
adjective - A description used to modify or describe a noun
Enter your amazing code here!
*/
// __Name__ is a __adjective__ __noun__. They are always __adverb__ __verb__
String name = console.readLine("Enter a name: ");
String adjective = console.readLine("Enter an adjective: ");
String noun = console.readLine("Enter a noun: ");
String adverb = console.readLine("Enter an adverb: ");
String verb = console.readLine("Enter a verb ending with -ing: ");
console.printf("Your TreeStory:\n-----\n");
console.printf("%s is a %s %s. ", name, adjective, noun);
console.printf("They are always %s %s. \n", adverb, verb);
}
}
In Dr. Java, I am unable to type in the console, but I am able to type in the "interactions" at the bottom of the Dr. Java IDE. Is this where I should be running:
clear && javac TreeStory.java && java TreeStory
I tried that but just received errors. Do I need to point to a directory perhaps?
Sorry for my newb questions.
2 Answers
Steve Hunter
57,712 PointsHi,
I just downloaded Dr Java to see the solution for this.
Have you tried clicking the compile button at the top (that does the javac bit) then the Run button?
I get an error but that's how the Dr Java thing is supposed to work, I think.
Steve.
Matthew McGeehan
995 PointsThank for the reply Steve,
I clicked the compile button, Compilation completed, then I clicked the run button and received this in my "interactions":
Welcome to DrJava. Working directory is /Users/"myname"/Desktop
run TreeStory java.lang.NullPointerException at TreeStory.main(TreeStory.java:15) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at edu.rice.cs.drjava.model.compiler.JavacCompiler.runCommand(JavacCompiler.java:272)
When I run the TreeStory.java in Terminal, the program works perfectly, but I was hoping to make it work in Dr. Java as well. Perhaps, there is a different syntax I should be using somewhere along the way. I'll do some googling and report back if I find an answer,
Thanks again Steve.