jijesh Aj
jijesh Aj

Reputation: 614

Type mismatch error upon compiling project with ScalaFX in SBT

I'm developing a project with ScalaFX and MySQL database.

SBT successfully added MySQL connector via build.sbt file. When it compiles the project, it stops with a type mismatch error:

[error]  found   : com.aitrich.scalafx.test.DbConnection.type (with underlying type object com.aitrich.scalafx.test.DbConnection)
[error]  required: com.aitrich.scalafx.test.DbConnection
[error]     val orders: Seq[Person] = OrderDao.getAllOrders(dbc)
[error]                                                     ^
[error] one error found
[error] (compile:compile) Compilation failed
[error] Total time: 14 s, completed Nov 14, 2013 12:04:06 PM

The following is a code snippet from the main method:

var dbc = DbConnection
val orders: Seq[Person] = OrderDao.getAllOrders(dbc)

This is the DbConnection case class:

case class DbConnection() {
  def getConnectionString = 
    "jdbc:mysql://%s:3306/simpleorder?user=%root&password=%sa".
      format("localhost","root","sa")
}

Why does compile fail?

Upvotes: 0

Views: 331

Answers (1)

Jacek Laskowski
Jacek Laskowski

Reputation: 74669

tl;dr You need to instantiate (create an instance of) DbConnection case class.

It's in no way SBT's or ScalaFX's issue.

What you pass as an argument to OrderDao.getAllOrders method is a type not an instance of a type. The types simply don't match and the Scala compiler breaks compilation (that's exactly the reason to use Scala in the first place - a thorough type checking at compile time).

Change the line

var dbc = DbConnection

to

var dbc = new DbConnection

and the compiler gets pass that line. Note the new keyword.

Upvotes: 1

Related Questions