-2

I am trying to run some scala code in eclipse but i got stuck with a weird problem. If no errors exist, it runs fine, otherwise it just gives the error: could not find or load main class .... What may cause such an annoying problem?

  package p


  object Main{
      def main(args: Array[String]): Unit = {
        ----
      }
    }

this snippet outputs:

Error: Could not find or load main class p.Main

I want to see something like this:

Error:(15, 5) not found: value --

sfwh
  • 37
  • 2
  • 8
  • Do you mean compilation errors? You can't run code if it still contains errors. – greg-449 May 26 '15 at 17:12
  • Of course i can't run .When there is no error, everything is fine but in case of any error it always prints in the console : error : could not find or load main class .... I just add a random character to see how it reacts, it gives me the same error regardless of the specisif problem. – sfwh May 26 '15 at 17:19
  • plop an example above of what bombs. give us something to work with – Drew May 26 '15 at 17:46
  • I've tried to attach an image but my reputation did not allow. Actually nothing complicated to showcase. All kinds of errors prints the same error message to console, the error written above. – sfwh May 26 '15 at 17:51
  • guess u can edit the question with a scala object block (in text format) showing a simple situation. edit the question above as opposed to 'adding a comment' below the question – Drew May 26 '15 at 18:16
  • If you put junk in the source file, do you get a compiler error - in other words, is it in the source path at all? – Ed Staub May 26 '15 at 21:25

1 Answers1

0

try

object HelloWorld {
  def main(args: Array[String]) {
    println("Hello, world!")
  }
}

omitting the Unit =. If that works, then it's the capture into Unit

In my estimation, the odds are high that you have a case mismatch. You defined class Main, which is p.Main but your error is for not finding p.main. Many systems are case sensitive, so if you are used to Windows style case insensitivity, you'll have to be vigilant.

Edwin Buck
  • 69,361
  • 7
  • 100
  • 138
  • It actually outputs p.Main. It was my fault, corrected it . Unit trick did not solve anything, it is irrelevant i guess. – sfwh May 26 '15 at 18:46
  • Often Eclipse runs things in the top level project directory. Odds are that's not where your Scala compiler output its classes. – Edwin Buck May 26 '15 at 18:53