4

I installed scala and scala IDE for eclipse. I get this message everytime I try to compile a simple "HelloWorld":

package asd

object testobject {
  def main(args: Array[String]): Unit = {
    println("asda");
  }
}

"Error: Mainclass asd.testobject could not be found"

New Scala Project -> asd

New Scala Object -> Copy&Paste the code above

Run As -> Scala Application

My problem is that I've tried literally everything I found on the internet and it wont work. I really dont know why it doesnt work. Main class in Runconfig: asd.testobject. I really hope that anyone of you can help me, I think I didnt include the environment or scala jre somewhere...??

scala -version : 2.11.6

EDIT:: @dragonborn I'm not quite sure what do you mean? I made a picture which shows my config for scala. Can you explain it?

I cannot post pictures here so here is the Link: scala config

Asdf11
  • 450
  • 5
  • 15

5 Answers5

3

Though it is Scala IDE :) it still expects the class scala file to be found in the right package dir.

e.g. testobject.scala should be part of src/main/scala/asd

We too had to change the scala file location for our app Main class to be able to debug it in Scala IDE. Small nuisance.

Dragonborn
  • 1,755
  • 1
  • 16
  • 37
  • I added a pic of how my package looks like, can you please explain to me, what excaclty you mean? – Asdf11 May 12 '15 at 15:40
  • I see no pic. Can you show the scala file as well as its place in the folder tree? – Dragonborn May 13 '15 at 05:44
  • I posted this its the sentence: "I cannot post pictures here so here is the Link: scala config" you can click there on scala config, and a picture will open ( I hope) – Asdf11 May 15 '15 at 08:48
  • Make sure the project is built without errors. Check the output directory manually. Any other files in your project? – Iulian Dragos May 16 '15 at 16:35
0

I do not use eclipse, but have you tried this way?

object Test extends App { println("hello world") }

Thiago Pereira
  • 1,724
  • 1
  • 17
  • 31
  • I get this Error Message using your code: overriding method main in trait App of type (args: Array[String])Unit – Asdf11 May 12 '15 at 15:04
0

Your class isn't set as a class that can be launched.

You need to extend App and put the body of your code directly in the class, like this:

package asd

object testobject extends App {
    println("asda");
}
tddmonkey
  • 20,798
  • 10
  • 58
  • 67
  • I just tried it, the Error stays the same: MainClass cannot be found :( Maybe something on my configuration is wrong? I made an edit an put a pic in it – Asdf11 May 12 '15 at 15:25
0

I just did a complete installation of Eclipse and the Scala IDE for Eclipse, created a runnable scala object using it and ran that object to produce the expected output with no problems. My installation platform is Windows 7 x86_64. This is what I did:

  1. downloaded eclipse-jee-luna-SR2-win32-x86_64.zip from Columbia University at the Eclipse downloads - mirror selection page at https://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/luna/SR2/eclipse-jee-luna-SR2-win32-x86_64.zip

  2. unbundled the download and updated its eclipse.ini file with -Xms256m and -Xmx2048m

  3. created a new workspace folder

  4. started eclipse by double clicking on eclipse.exe in the folder of the unbundled download and entered the pathname of the new workspace folder in its Workspace Launcher's Select a workspace pop-up when it became available

  5. in the running eclipse selected Help > Install New Software... to get the Available Software pop-up, clicked on Add in it to get the Add Repository pop-up and in that added the URL for the Scala IDE for Eclipse4.4 (Luna) For Scala 2.11.6 provided at http://scala-ide.org/download/current.html (the IDE repo URL is http://download.scala-ide.org/sdk/lithium/e44/scala211/stable/site) giving it the name "Scala IDE for Eclipse4.4 (Luna) For Scala 2.11.6" and clicked OK.

  6. in the resulting Available Software pop-up selected everything visible (Scala IDE for Eclipse, Scala IDE for Eclipse Development Support, Scala IDE for Eclipse Source Feature, Scala IDE Plugins (incubation) and Sources), clicked on Next and clicked on Finish

  7. after the installation finished it was required to restart Eclipse so I did that

  8. after the restart finished, in the running eclipse opened the scala perspecive by selecting Window > Open Perspective > Other > Scala

  9. created a new scala project by selecting File > New > Scala Project, giving it the name "HelloWorld" and clicked on Finish

  10. in the HelloWorld project right clicked on src and selected New > Package, entered "tn" and clicked on Finish

  11. right clicked on the tn package in HelloWord/src, selected New > Scala Object, gave it the name "HelloWorld" and clicked on Finish

  12. in the editor window of the HelloWorld object that came up, added "extends App" to the object's definition and println("hello world") in its body. Here are the contents of the HelloWorld.scala file:

    package tn
    
    object HelloWorld extends App {
      println("hello world")
    }
    
  13. ran the HelloWorld object by right clicking in its editor window and selecting Run As > Scala Application which caused "hello world" to be printed in the Console view

  • I have no Errors, my run config is in the pic in my post. I did the whole JDT weaving Setup, i still get the message couldnt find main class! – Asdf11 May 15 '15 at 09:02
  • What operating system are you running Eclipse on? –  May 16 '15 at 15:41
0

If your scala source has a main Object like this:

package org.xx.yy

object MyPackage extends App {
}

Then in Eclipse IDE set "Debug configurations->Scala Application->Main class" to "org.xx.yy.MyPackge"

Peluo
  • 11
  • 3