This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Constructor not working (init NOT found...)

3 replies
DamonF
Joined: 2009-01-03,
User offline. Last seen 42 years 45 weeks ago.

I have what must be the ultimate newbie question.... My 'object' class is
not finding the class constructor I expected, with either an empty explicit
constructor or a String parameter as the primary constructor. Here are the
class, object and output.

Can anyone tell what I'm doing wrong? I'm using the eclipse plugin, if that
matters.

thanks,
Damon

--

package misc
class Hello {
def greet() = println("Hello, ")
}

--
package misc
object Hello {
def main(args: Array[String]) {
new Hello
}
}

--
Exception in thread "main" java.lang.NoSuchMethodError: misc.Hello: method
()V not found
at misc.Hello$.main(HelloObj.scala:5)
at misc.Hello.main(HelloObj.scala)

Ricky Clarkson
Joined: 2008-12-19,
User offline. Last seen 3 years 2 weeks ago.
Re: Constructor not working (init NOT found...)
Care to mention a version number?  It works for me from the Scala interpreter on current svn trunk.

2009/1/3 DamonF <damonfeldman [at] verizon [dot] net>

I have what must be the ultimate newbie question....  My 'object' class is
not finding the class constructor I expected, with either an empty explicit
constructor or a String parameter as the primary constructor.  Here are the
class, object and output.

Can anyone tell what I'm doing wrong?  I'm using the eclipse plugin, if that
matters.

thanks,
Damon

--

package misc
class Hello {
 def greet() = println("Hello, ")
}

--
package misc
object Hello {
 def main(args: Array[String]) {
   new Hello
 }
}

--
Exception in thread "main" java.lang.NoSuchMethodError: misc.Hello: method
<init>()V not found
       at misc.Hello$.main(HelloObj.scala:5)
       at misc.Hello.main(HelloObj.scala)

--
View this message in context: http://www.nabble.com/Constructor-not-working-%28init-NOT-found...%29-tp21267296p21267296.html
Sent from the Scala - User mailing list archive at Nabble.com.


DamonF
Joined: 2009-01-03,
User offline. Last seen 42 years 45 weeks ago.
Re: Constructor not working (init NOT found...)

I'm running scala-2.7.1.final.

I have also run using the eclipse plugin 2.7.2RC1 and 2.7.3RC1, which may
have their own internal scala distros (and a couple quirks about when they
rebuild classes, it seems).

I have stumbled beyond the problem, though still don't fully understand the
issue. I renamed the object to "Helloo" and added an explicit import of
misc.Hello (the class) to misc.Heloo (the object).

Ricky Clarkson wrote:
>
> Care to mention a version number? It works for me from the Scala
> interpreter on current svn trunk.
>
> 2009/1/3 DamonF
>>
>> I have what must be the ultimate newbie question.... My 'object' class
>> is
>> not finding the class constructor I expected,
>

Alex Cruise
Joined: 2008-12-17,
User offline. Last seen 2 years 26 weeks ago.
Re: Constructor not working (init NOT found...)

Quoting DamonF :
> I have stumbled beyond the problem, though still don't fully understand the
> issue. I renamed the object to "Helloo" and added an explicit import of
> misc.Hello (the class) to misc.Heloo (the object).

IIUC in order for an object to serve as a "companion object" to a
class they should be defined in the same source file. In your case
the class's default constructor *should* be public, but without having
read the spec, I'd recommend avoiding defining classes and objects
with the same name in *different* files.

-0xe1a

----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland