简体   繁体   English

JAVA FX ObservableList无法初始化

[英]JAVA FX ObservableList cannot initialise

i am creating a TableView in JAVA FX and i have a class Phone to represent my data like the documentation said . 我正在JAVA FX中创建TableView,并且有一个Phone类来表示我的数据,如文档所述。 the phone class has a SimpleStringProperty phoneName. 电话类具有SimpleStringProperty phoneName。 in the documentation they make the class phone static and the property final. 在文档中,它们使类phone变为静态,而属性变为final。 if i make the class static i have an error modifier static not allowed here if i make the property final i can't create setters but in the doc they do 如果我将类设为静态,则将错误修饰符设为static,如果我将属性设为final,则无法创建setter,但在文档中却可以

and in my application when a create an ObservableList of phones , when i put data in it like below : 在我的应用程序中,当创建数据的ObservableList时,如下所示:

 private ObservableList<Phone> phoneList = FXCollections.observableArrayList(          
        new Phone( "iphone" , "ios")  ,
        new Phone("nexus" , "android") 
          );

i have an error saying : cannot convert String to SimpleStringProperty 我有一个错误说:无法将字符串转换为SimpleStringProperty

Thx u . 谢谢你 。 not that if i remove the static and final keywords and change the properties to normal String , it works but i'am having problems after when i want to make the table editable like i explain here related question 不是说如果我删除static和final关键字并将属性更改为Normal String,它可以工作,但是当我想使表格可编辑时出现问题,就像我在这里解释相关问题一样

Thx u guys 谢谢你们

The Song constructor need to look like this : Song构造函数需要如下所示:

public Song(String model,String os){

this.model = new SimpleStringProperty(model);
this.os = new SimpleStringProperty(os);

}

You need to create the SimpleStringProperty with your string. 您需要使用字符串创建SimpleStringProperty。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM