tags:

views:

5997

answers:

7

Hello folks,

Just going through the sample Scala code on Scala website, but encountered an annoying error when trying to run it.

Here's the code: http://www.scala-lang.org/node/45. On running it on Eclipse, I get this 'Editor does not contain a main type' that prevents it from running.

Is there anything I need to do...i.e break that file into multiple files, or what?

+2  A: 

That code is valid. Have you tried to compile it by hand using scalac? Also, have you called your file "addressbook", all lowercase, like the name of the object?

Also, I found that Eclipse, for some reason, set the main class to be ".addressbook" instead of "addressbook".

Daniel
Thanks Daniel, yes the file is named 'addressbook' all lowercase. Will try reopening the project to see if that helps.
Helen Neely
+8  A: 

I have this prolbem a lot with Eclipse and Scala. It helps if you clean your workspace and rebuild your Project.

Some times Eclipse doesn't recognize correctly which files it has to recompile :(

Edit: The Code runs fine in Eclipse

nuriaion
Made the same experience. Plus closing and opening the project seemed to be required for me sometimes.
Fabian Steeg
Thanks guys, I will try closing and reopening the project to see if that helps.
Helen Neely
Thanks @nuriaion and @Fabian, yes, reopening the project got it working. Thanks again for your tips.
Helen Neely
@Helen In Eclipse => Project => Clean you can clean the projects, the rebuild will run automaticaly... So you don't have to close and reopen the project.
nuriaion
@nuriaion thatnks for solving this problem at my work ;)
alexanderpas
+1  A: 

I just had this problem too. The solution is to make sure eclipse created the project as Java project. Just create a new Java project and copy your class into the src folder (and import the eventual dependencies). This should fix the problem.

KullDox
Thanks KullDox, for your comment. I've long solved the issue but hope someone else finds the solutions here helpful.
Helen Neely
A: 

@KullDox' Comment (There is no reply button for me to write directly under someones post): If I create it as a java project then Eclipse treats the file as a java file and can't run Scala code.

A: 

A simplier way is to close your project and reopen it !

static
A: 

@user398963, sorry, I'm not familiar with Scala but I see there are Scala IDE plugins for Eclipse (link text). Thus for it I think you can create a Scala Project instead.

KullDox
A: 

You simply have to select the root of the project in the projects tree before you press the run button. If you've got the focus on any other file, Eclipse tries to compile this file somehow, instead of the project. I've put a description of this problem and it's solution on my blog www.wassmuth.ch.