"Editor does not contain a main type" error pressing the Run-Button
Hi,
the following code :
results in a Messagebox with the above menitoned error message in Eclipse 3.5.2
As I'm a Scala newbie and did not work with C and related language systems before, I first verified that I did not misunderstood something by posting the problem first in the Scala-User Forum. The answers there were clear: Code is ok, problem off the IDE.
Thus I checked the Eclipse error log and got the below event details.
In case that further information is needed, just send an email to: johe-dot-infotech-at-gmail-dot-com
Joe Herrmann
the following code :
package RationalPack
object MyMain {
def main(args:Array[String]){
val x=new Rational(49,13)
val y=new Rational(47,128)
println (x + "+" + y +"=" + x.+(y) )
println (x + "*" + y +"=" + x*y )
}
}
results in a Messagebox with the above menitoned error message in Eclipse 3.5.2
As I'm a Scala newbie and did not work with C and related language systems before, I first verified that I did not misunderstood something by posting the problem first in the Scala-User Forum. The answers there were clear: Code is ok, problem off the IDE.
Thus I checked the Eclipse error log and got the below event details.
In case that further information is needed, just send an email to: johe-dot-infotech-at-gmail-dot-com
Joe Herrmann
eclipse.buildId=M20100211-1343
java.version=1.6.0_20
java.vendor=Sun Microsystems Inc.
BootLoader constants: OS=win32, ARCH=x86, WS=win32, NL=en_GB
Command-line arguments: -os win32 -ws win32 -arch x86
Error
Fri Aug 27 11:20:03 GMT+04:00 2010
Failure in presentation compiler
scala.tools.nsc.MissingRequirementError: object scala not found.
at scala.tools.nsc.symtab.Definitions$definitions$.getModuleOrClass(Definitions.scala:513)
at scala.tools.nsc.symtab.Definitions$definitions$.ScalaPackage(Definitions.scala:37)
at scala.tools.nsc.symtab.Definitions$definitions$.ScalaPackageClass(Definitions.scala:38)
at scala.tools.nsc.symtab.Definitions$definitions$.UnitClass(Definitions.scala:83)
at scala.tools.nsc.symtab.Definitions$definitions$.init(Definitions.scala:785)
at scala.tools.nsc.Global$Run.<init>(Global.scala:597)
at scala.tools.nsc.interactive.Global$TyperRun.<init>(Global.scala:473)
at scala.tools.eclipse.ScalaPresentationCompiler$EclipseTyperRun.<init>(ScalaPresentationCompiler.scala:112)
at scala.tools.eclipse.ScalaPresentationCompiler.newTyperRun(ScalaPresentationCompiler.scala:155)
at scala.tools.eclipse.ScalaPresentationCompiler.newTyperRun(ScalaPresentationCompiler.scala:26)
at scala.tools.nsc.interactive.Global.reloadSources(Global.scala:289)
at scala.tools.nsc.interactive.Global.typedTree(Global.scala:319)
at scala.tools.nsc.interactive.Global$$anonfun$getTypedTree$1.apply(Global.scala:331)
at scala.tools.nsc.interactive.Global$$anonfun$getTypedTree$1.apply(Global.scala:331)
at scala.tools.nsc.interactive.Global.respond(Global.scala:276)
at scala.tools.nsc.interactive.Global.getTypedTree(Global.scala:331)
at scala.tools.nsc.interactive.CompilerControl$$anon$3.apply$mcV$sp(CompilerControl.scala:95)
at scala.tools.nsc.interactive.Global.pollForWork(Global.scala:132)
at scala.tools.nsc.interactive.Global$$anon$2.run(Global.scala:192)
Leave a comment
on 2010-08-27 08:36 *
By
That isn't a complete program (there's no definition for the type Rational), so I wouldn't expect it to be compilable or runnable as it stands.
Nevertheless, I think you have a different problem ... the stacktrace implies that you're missing the reference to the Scala library in your project .classpath file. How did you create this project? Can you show us the contents of your .project and .classpath files. Thanks.
Nevertheless, I think you have a different problem ... the stacktrace implies that you're missing the reference to the Scala library in your project .classpath file. How did you create this project? Can you show us the contents of your .project and .classpath files. Thanks.
Hi Miles,
thanks for your response.
The class Rational exists in the same project and I simply wanted to publish things which are obviously related to the problem ... from my point of view.
I'm using Win XP pro and have set the enviroment variables as follows:
JAVA_HOME = C:\Program Files\Java\jdk1.6.0_20
SCALA_HOME = E:\Java\Scala\scala-2.8.0.final
CLASSPATH = E:\Java\workspace;%JAVA_HOME%
Path = %JAVA_HOME%\bin;%SCALA_HOME%\bin; ...{all the other pathes}...
Here is the class :
Here comes the *.classpath* file in the project subdir:
...and last but not least ... *.project*
thanks for your response.
The class Rational exists in the same project and I simply wanted to publish things which are obviously related to the problem ... from my point of view.
I'm using Win XP pro and have set the enviroment variables as follows:
JAVA_HOME = C:\Program Files\Java\jdk1.6.0_20
SCALA_HOME = E:\Java\Scala\scala-2.8.0.final
CLASSPATH = E:\Java\workspace;%JAVA_HOME%
Path = %JAVA_HOME%\bin;%SCALA_HOME%\bin; ...{all the other pathes}...
Here is the class :
package RationalPack
/**
* Implements Rational numbers. Calculates the Greatest Common Denominator and
* stores the values in shortened form. Written in Scala
* @param n numerator (int)
* @param d denominator (int)
* @return a rational object
* @throws nothing
* @version 1.0
*/
class Rational(n:Int, d:Int) extends Ordered[Rational] {
require(d!=0)
private val g=gcd(n.abs, d.abs)
val numer = n / g
val denom = d / g
def this(n:Int)= this(n,1)
def + (that:Rational):Rational=
new Rational(
numer*that.denom+that.numer*denom,
denom*that.denom)
def + (i:Int):Rational =
new Rational(numer + i *denom,denom)
def - (that:Rational):Rational =
new Rational(
numer*that.denom - that.numer*denom,
denom*that.denom)
def - (i:Int):Rational =
new Rational(numer-i*denom,denom)
def * (that:Rational):Rational =
new Rational(numer*that.numer,denom*that.denom)
def * (i:Int):Rational =
new Rational(numer*i,denom)
def / (that:Rational):Rational=
new Rational(numer*that.denom, denom*that.numer )
def / (i:Int):Rational =
new Rational(numer,denom*i)
def compare(that:Rational)=(this.numer*that.denom)-(that.numer*this.denom )
override def toString=numer +"/"+ denom
implicit def intToRational(x:Int)=new Rational(x)
private def gcd(a:Int, b:Int):Int =
if(b==0) a else gcd(b, a%b)
}
Here comes the *.classpath* file in the project subdir:
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="ch.epfl.lamp.sdt.launching.SCALA_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="output" path="bin"/>
</classpath>
...and last but not least ... *.project*
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>RationalNumbers</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>ch.epfl.lamp.sdt.core.scalabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>ch.epfl.lamp.sdt.core.scalanature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
on 2010-08-27 14:49 *
By
In your .classpath file, could you change the line,
to read,
<classpathentry kind="con" path="ch.epfl.lamp.sdt.launching.SCALA_CONTAINER"/>
to read,
<classpathentry kind="con" path="org.scala-ide.sdt.launching.SCALA_CONTAINER"/>
on 2010-08-27 15:14 *
By
Neither do I at the moment ... the old id is supposed to still be working. Presumably you created the project a little while ago and then it stopped working recently when you upgraded the Scala IDE?
So, what is the fix, then? Do we expect people who upgrade to manually go and edit all their project files? I fear that many will not be so persistent to even find out what the problem is, and will turn their backs in frustration, instead. With some justification.
I wasted a number of hours myself, on this problem.
I wasted a number of hours myself, on this problem.
Joe-eoJ was a bit too quick off the mark closing this. I've just now committed a fix in revision:446d97343779294157b69bff067e6a30b38f02f7 ... projects using the old ids will now behave sensibly in recent builds of the SDT. The change will show up in tomorrow's nightly build.