Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala import not working - object <name> is not a member of package, sbt preppends current package namespace in imports

Tags:

scala

I have an issue when trying to import in scala. The object Database exists under com.me.project.database but when I try to import it:

import com.me.project.database.Database 

I get the error:

object Database is not a member of package com.me.project.controllers.com.me.project.database 

Any ideas what the problem is?

Edit:

It is worth mentioning that the import is in the file Application.scala under the package com.me.project.controllers, I can't figure out why it would append the import to the current package though, weird...

Edit 2:

So using:

import _root_.com.me.project.database.Database 

Does work as mentioned below. But should it work without the _root_? The comments so far seem to indicate that it should.

Answer:

So it turns out that I just needed to clean the project for the import to work properly, using both:

import _root_.com.me.project.database.Database  import com.me.project.database.Database 

are valid solutions. Eclipse had just gotten confused.

like image 797
Neilos Avatar asked Feb 11 '14 12:02

Neilos


2 Answers

imports can be relative. Is that the only import you have? be careful with other imports like

import com.me

ultimately, this should fix it, then you can try to find more about it:

import _root_.com.me.project.database.Database

like image 93
fracca Avatar answered Sep 19 '22 18:09

fracca


In my case I also needed to check that object which is not found as a member of package is compiled successfully.

like image 34
Bunyk Avatar answered Sep 23 '22 18:09

Bunyk