Merion
Merion

Reputation: 741

Play Framework The type ... is already defined

When I try to run my Application it gives me following error:

Compilation error
The file /app/models/setting.java could not be compiled. Error raised is : The type Setting is already defined

I am running play on windows. Is it possible that play has problems with windows' case insensitive? So it would first try to compile models/Setting.java and after that models/setting.java ??

What else could be the reason for this odd behavior?

/EDIT: Since i wrote this question here i did not edit anything at my play application and i did not restart it. Now i just refreshed the page and the same error comes again - but with another model!!

The file /app/models/staticsite.java could not be compiled. Error raised is : The type Staticsite is already defined

/EDIT2: After a few page refreshes in the browser this error appeared:

The file /app/models/setting.java could not be compiled. Error raised is : The public type Setting must be defined in its own file

The file IS named "Setting.java" and the class IS named Setting

Upvotes: 2

Views: 6746

Answers (5)

Kyle Buzsaki
Kyle Buzsaki

Reputation: 23

I had this issue while trying to resolve merge conflicts in git. I missed a change, and was getting this compiler error.

The issue was that I had a variable of type ClassName named className. The variable had been deleted but this particular line was still trying to access it. Instead of reporting that the className variable did not exist, Play did some black magic and ended up reporting the name conflict above: "Type ClassName is already defined". There was some kind of name conflict with the ClassName class and the className variable.

The fix was to just alter that line, removing the incorrect access to the old className variable. Then run play clean and restart your server.

Upvotes: 0

seePatCode
seePatCode

Reputation: 472

"The type is already defined" exceptions can be raised when the issue is outside of the mentioned class. If your class name matches (case-sensitive) and it is defined in its own file, your next step is to find out what code has recently changed that references this class. For me, the issue was that my file, "utils.Utils.java", had been imported in another file via "import utils.Utils;" which really confused the compiler when I referenced "utils.Utils.someMethod()" in the code. I changed the line to "Utils.someMethod()" and the exception disappeared.

I probably should have come up with a better naming scheme. :/

Upvotes: 4

Gugan Mohan
Gugan Mohan

Reputation: 1645

This error happens when you rename the class file that you try to compile. Simply re run the play frame work after you refract the class name. This will fix the issue.

Upvotes: 2

Chema
Chema

Reputation: 11

I think you are working with settings.someProperty whithout declare the object "settings", and play is thinking it's a static method of the class "Settings" with an error in the capital letter.

Upvotes: 1

Marius Soutier
Marius Soutier

Reputation: 11274

Did you have a settings.java and replaced it with Settings.java? Anyway, try play clean.

If that doesn't work, check very carefully that you don't have any problematic invisible characters in your file.

Upvotes: 1

Related Questions