Incompatible types. When using PropertyValueFactory in JavaFX

1,231 views
Skip to first unread message

Micael Pedrosa

unread,
Jul 13, 2012, 10:14:08 AM7/13/12
to xtend...@googlegroups.com
My normal java code is (works fine):
final TableColumn<Person, String> firstNameCol = new TableColumn<>("First Name");
firstNameCol.setCellValueFactory(new PropertyValueFactory<Person, String>("firstName"));

final TableView<Person> table = new TableView<>();
table.getColumns().add(firstNameCol);

I was trying to convert to xtend with:
new TableView<Person> => [
columns += new TableColumn<Person, String>("First Name") => [
cellValueFactory = new PropertyValueFactory<Person, String>("firstName")
]
]

but gives me an error:
Incompatible types. Expected javafx.util.Callback<javafx.scene.control.TableColumn.CellDataFeatures<fx.ui.test.Person, java.lang.String>, javafx.beans.value.ObservableValue<java.lang.String>> but was javafx.scene.control.cell.PropertyValueFactory<fx.ui.test.Person, java.lang.String>

Micael Pedrosa

unread,
Jul 24, 2012, 7:55:54 PM7/24/12
to xtend...@googlegroups.com
Any suggestions? It seems that it breaks the 100% java compatibility!

Vlad Dumitrescu

unread,
Jul 25, 2012, 2:25:54 AM7/25/12
to xtend...@googlegroups.com
Hi!
This works for me:

class Demo {
def demo() {
new TableView<Person> => [
columns += new TableColumn<Person, String>("First Name") => [
cellValueFactory = new PropertyValueFactory<Person, String>("firstName")
]
]
}
}

class TableView<T> {
public List<TableColumn<T, String>> columns
}

class Person {

}

class TableColumn<P, S> {
new (S s) {
}
public PropertyValueFactory<P,S> cellValueFactory
}

class PropertyValueFactory<P, S> {
new(S s) {
}
}

Maybe you have other field named cellValueFactory in your current
("Demo") class and it is used instead of the one in TableColumn? Try
prefixing the fields with "it."

regards,
Vlad

Micael Pedrosa

unread,
Jul 25, 2012, 4:17:23 PM7/25/12
to xtend...@googlegroups.com
No other field with this name. Tried with "it", not working.
I noticed that you are creating your own classes. Maybe javafx classes and methods are defined in different way!

Vlad Dumitrescu

unread,
Jul 25, 2012, 4:24:38 PM7/25/12
to xtend...@googlegroups.com
Hi,

On Wed, Jul 25, 2012 at 10:17 PM, Micael Pedrosa
<micael...@gmail.com> wrote:
> No other field with this name. Tried with "it", not working.
> I noticed that you are creating your own classes. Maybe javafx classes and
> methods are defined in different way!

If it's still JVM classes, so it should not matter... I don't have
javafx installed, so I can't test your code. Does it work for you with
my mockup classes?

regards,
Vlad

Micael Pedrosa

unread,
Jul 26, 2012, 5:26:32 AM7/26/12
to xtend...@googlegroups.com
Yes, but as I said, Maybe javafx classes and methods are defined in different way!
For example PropertyValueFactory implements javafx.util.Callback.


On Wednesday, July 25, 2012 8:24:38 PM UTC, Vlad Dumitrescu wrote:
Hi,

On Wed, Jul 25, 2012 at 10:17 PM, Micael Pedrosa

Micael Pedrosa

unread,
Jul 26, 2012, 5:29:50 AM7/26/12
to xtend...@googlegroups.com
And, it works fine with your defined classes.
Reply all
Reply to author
Forward
0 new messages