Scala outputs on the command-line, but not in Eclipse Scala IDE
Question
I don't know what's going on or even how to figure it out, but I have a Scala Hello World object, like this.
object TestFoo {
def main(args: Array[String]): Unit = {
println("Hello World")
}
}
The Scala IDE for Eclipse (for Scala 2.9, running Eclipse Indigo) shows no errors and has created a compiled class. When I go to Run > Run As > Scala Application, the terminal console shows no output. However, when I go to the command-line and run scala directly (using the class file Eclipse compiled), I get the correct output:
% scala -cp bin/classes TestFoo
Hello World
Any ideas on what I may have done wrong or can do to correct the problem so that output shows up in Eclipse?
Update: I checked the Console output from Eclipse to see if there was anything usual there after one of the commenters suggesting checking the error log. I see a crash report for Java, with this as the exception:
Java information:
Exception type: Internal Error (/SourceCache/JavaJDK16/JavaJDK16-424/hotspot/src/share/vm/runtime/fieldDescriptor.cpp, line 85)
# guarantee(_name_index != 0 && _signature_index != 0) failed: bad constant pool index for fieldDescriptor
La solution
Okay, so after further investigation it appears that everything was working correctly so long as I use a Scala project for doing the work. It might also work with a typical Java project running a mix of Scala and Java.
In this case, I was trying to get a test script running in an Android project and it cannot find the terminal there at all and has the exception reported. That's what I was doing wrong.
If you are having trouble running a console app from within an Android project or some other non-Scala project, that's probably the problem. Use a Scala project for such things.