"Could not find or load main class " error message in scala akka with eclipse IDE

7,120 views
Skip to first unread message

Balakrishnan subramanian

unread,
Apr 22, 2014, 12:17:43 PM4/22/14
to scala-i...@googlegroups.com
Here is my test code,written based on the scala akka example from documentation 2.0.4 mentioned on their website. On excuting the example,the Eclipse throuws error stating "Could not find or load main class " error message. Sorry about the cross positing,but i could not fiind any solution to this issue anywhere. 

Eclipse version:  Eclipse IDE for Java Developers 2.0.2.20140224-0000 ( Kepler Service Release 2 )
Scala IDE plugin version :   Scala IDE for Eclipse 3.0.3.v-2_10-201403271605-8d2c756
Scala version:2.10.3
Akka jar version : akka-actor_2.10-2.1.4


import akka.actor.Actor
import akka.actor.ActorRef
import scala.collection.mutable.ListBuffer
import akka.actor.Props
import akka.routing.RoundRobinRouter
import akka.actor.ActorSystem

object AkaObj extends App{


process()

sealed trait PiMessage
case class Work(value:String) extends PiMessage
case class printComp(valu:String)extends PiMessage
case object Start extends PiMessage 
case class ListObj(cont:Seq[String]) extends PiMessage


class Worker extends Actor{

  def receive()={

    case Work(value:String)=>
      println(value)
      sender ! printComp(value)
  }
}

class Master(listener: ActorRef) extends Actor{

  val nrOfWorkers = 10
  var counter = 0
  var lis = ListBuffer[String]()

  val workerRouter = context.actorOf(
  Props[Worker].withRouter(RoundRobinRouter(nrOfWorkers)), name = "workerRouter")

  def receive()={
    //handle message
    case Start=>workerRouter ! Work("Start now " + System.currentTimeMillis())
    case printComp(value:String)=> { 
      counter+=1
      lis.append(counter+"-"+value)
      if(counter >=10)
          listener ! ListObj(lis.toSeq)

      // Stops this actor and all its supervised children
      context.stop(self)
      }
  }
 }

class Listener extends Actor{

  def receive()={

    case ListObj(cont:Seq[String])=>
      println("Completed " +cont)
      context.system.shutdown()
  }
}

def process(){
  // Create an Akka system
    val system = ActorSystem("PiSystem")

  // create the result listener, which will print the result and shutdown the system
    val listener = system.actorOf(Props[Listener], name = "listener")

  // create the master
    val master = system.actorOf(Props(new Master(listener)),
      name = "master")

  // start the calculation
    master ! Start
}

}

Simon Schäfer

unread,
Apr 22, 2014, 1:06:55 PM4/22/14
to scala-i...@googlegroups.com
Does your project have a Scala nature?

Does a "object X extends App" in a new file, maybe even in a new project work?


On 04/22/2014 06:17 PM, Balakrishnan subramanian wrote:
Here is my test code,written based on the scala akka example from documentation 2.0.4 mentioned on their website. On excuting the example,the Eclipse throuws error stating "Could not find or load main class " error message. Sorry about the cross positing,but i could not fiind any solution to this issue anywhere. 

Eclipse version:  Eclipse IDE for Java Developers 2.0.2.20140224-0000 ( Kepler Service Release 2 )
Scala IDE plugin version :   Scala IDE for Eclipse 3.0.3.v-2_10-201403271605-8d2c756
Scala version:2.10.3
Akka jar version : akka-actor_2.10-2.1.4
import akka.actor.Actor
import akka.actor.ActorRef
import scala.collection.mutable.ListBuffer
import akka.actor.Props
import akka.routing.RoundRobinRouter
import akka.actor.ActorSystem

object AkaObj extends App{


process()

sealed trait PiMessage
case class Work(value:String) extends 
<
span class="typ" style="background-color: transparent; color: rgb(43, 145, 175);">PiMessage
--
You received this message because you are subscribed to the Google Groups "Scala IDE User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-ide-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/scala-ide-user/3e818e48-6c8a-48b8-a603-3bf6f05fc874%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Balakrishnan subramanian

unread,
Apr 22, 2014, 1:15:21 PM4/22/14
to scala-i...@googlegroups.com
Yes the project has scala nature,also has scala lib in its path. i have tested this code as new project ,also tried to run the file in scala cmd. Stil i have the same error message

Simon Schäfer

unread,
Apr 22, 2014, 1:31:36 PM4/22/14
to scala-i...@googlegroups.com
Eclipse can't execute your program if it doesn't find a main method, therefore I can only guess what's wrong.

Does it work with an explicit main method? Maybe your file is in a package, but you have no package declaration at the top of your file? Did you look if in the error view an error is shown?

And how did you install the Scala IDE? Maybe there went something wrong in the installation process.

iulian dragos

unread,
May 1, 2014, 1:17:55 PM5/1/14
to scala-i...@googlegroups.com
On Tue, Apr 22, 2014 at 8:31 PM, Simon Schäfer <ma...@antoras.de> wrote:
Eclipse can't execute your program if it doesn't find a main method, therefore I can only guess what's wrong.

Does it work with an explicit main method? Maybe your file is in a package, but you have no package declaration at the top of your file? Did you look if in the error view an error is shown?

I believe the problem is the missing package declaration. The "empty" (default) package is not very reliable. Otherwise, there might be a compilation error (maybe in tests?) that prevents the compiler from generating classfiles.

cheers,
iulian
 

For more options, visit https://groups.google.com/d/optout.



--
« Je déteste la montagne, ça cache le paysage »
Alphonse Allais

pankaj suryavanshi

unread,
Jan 11, 2018, 1:17:56 AM1/11/18
to Scala IDE User
Hi Bala,

Were you able to solve this problem?

I am very new to Scala, and I am also seeing this error : "Error: Could not find or load main class Main.scala"

Thanks
Reply all
Reply to author
Forward
0 new messages