Play Framework: incompatible types: java.util.List<models.Vehicle> cannot be converted to java.lang.String

I'm trying a simple view in Play framework 2.5 but I keep getting this compile-time error java.util.List<models.Vehicle> cannot be converted to java.lang.String

I already tried this answer

scala.collection.immutable.List<String> ls = JavaConverters.asScalaBufferConverter(scripts).asScala().toList(); 

but there is no .toList() function, it is not recognised. This is my code:

Aplication.java

package controllers;

import models.Vehicle;
import play.mvc.Controller;
import play.mvc.Result;
import scala.collection.JavaConverters;

public class Application extends Controller {

    public Result index() {
    //        this does not work
    //        scala.collection.immutable.List<Vehicle> ls = JavaConverters.asScalaBufferConverter(Vehicle.finder.all()).asScala().toList();
              return ok(views.html.index.render(Vehicle.finder.all())); //here is the error
    }

}

index.scala.html

@(vehicles: java.util.List[Vehicle])

@main("Welcome to Play") {

    <header>
        <hgroup>
            <h1>Dashboard</h1>
            <h2>Vehicles</h2>
        </hgroup>
    </header>

    <ul>
    @for(vehicle <- vehicles) {
        <li>@vehicle.getModel</li>
    }
    </ul>
}

relevant code in Vehicle.java

package models;

import javax.persistence.*;
import java.util.List;
@Entity
public class Vehicle extends BaseEntity {

    public static Finder<Long, Vehicle> finder = new Finder<Long, Vehicle>(Vehicle.class){};
    @Column(nullable = false)
    String model;

    public String getModel() {
        return model;
    }

    public void setModel(String model) {
        this.model = model;
    }
}

Any help would be highly appreciated.

Upvotes: 0

Views: 1415

Answers (1)

Okay, so in case anyone finds this in the future, try

activator clean compile

in your project folder.

Doing only compile did not help at all.

Upvotes: 1

Related Questions