Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/363.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JavaFX TableView整数未显示_Java_Javafx_Tableview - Fatal编程技术网

JavaFX TableView整数未显示

JavaFX TableView整数未显示,java,javafx,tableview,Java,Javafx,Tableview,我对JavaFX中的tableview有问题 出于某种原因,我的TableView没有显示一个整数的Inventory列,我已经运行了一些测试&这是因为没有执行getInventory函数 Java代码 //主类 公共类主扩展应用程序{ 舞台窗口; 场景1、场景2; VBox面板; 表视图表; 公共静态void main(字符串[]args){ 发射(args); } @凌驾 public void start(Stage)引发异常{ //舞台 窗口=舞台; setTitle(“测试应用程序-T

我对JavaFX中的tableview有问题

出于某种原因,我的TableView没有显示一个整数的Inventory列,我已经运行了一些测试&这是因为没有执行getInventory函数

Java代码

//主类
公共类主扩展应用程序{
舞台窗口;
场景1、场景2;
VBox面板;
表视图表;
公共静态void main(字符串[]args){
发射(args);
}
@凌驾
public void start(Stage)引发异常{
//舞台
窗口=舞台;
setTitle(“测试应用程序-TableView”);
//表列
TableColumn name_c=新的TableColumn(“资源名称”);
名称设置最小宽度(200);
名称c.setCellValueFactory(新属性ValueFactory(“名称”);
//---------------------------------------------
TableColumn价格=新的TableColumn(“资源价格”);
价格设置最小宽度(125);
price_c.setCellValueFactory(新财产价值工厂(“价格”);
//---------------------------------------------
TableColumn存货_c=新的TableColumn(“资源存货”);
库存设置最小宽度(125);
存货c.设置单元价值工厂(新财产价值工厂(“存货”);
//桌面视图
table=新的TableView();
table.getColumns().addAll(名称、价格、存货);
table.setItems(getResources());
//VBox
面板=新的VBox();
panel.getChildren().add(表);
//场面
场景=新场景(面板,500250);
window.setScene(场景);
window.show();
}
公共可观察列表getResources(){
//将值插入到TableView中
ObservableList res=FXCollections.observableArrayList();
res.add(新资源(“木材”),9.99100);
res.add(新资源(“铁”,12.85,70));
res.add(新资源(“棉花”,3.16200));
res.add(新资源(“大理石”,20.75,50));
res.add(新资源(“玻璃”,5.99175));
返回res;
}
}
//资源类
公共类资源{
私有字符串名称;
私人双价;
私人库存;
//建设者
公共资源(){
this.name=“”;
这个价格=0;
这意味着库存=0;
}
公共资源(字符串n,双p,整数i){
this.name=n;
这个价格=p;
这是库存=i;
}
//接球手和接球手。
公共字符串getName(){
返回名称;
}
公共无效集合名(字符串nm){
this.name=nm;
}
公开双价{
退货价格;
}
公共定价(双倍市价){
这个价格=pr;
}
public int getinventory(){
System.out.println(inventory);//库存测试(数据不显示,与其他get函数一起使用)
退货库存;
}
公共无效设置库存(内部库存){
这是库存=库存;
}
}

这可能是因为您有
getInventory()
方法,而不是
getInventory()

根据以下文件:

如果不存在与此模式匹配的方法,则对尝试调用
get()
is()
(即上面示例中的getFirstName()或isFirstName())的支持将失效


而且,您没有匹配的模式,即
getInventory()
inventoryProperty()

非常感谢,它现在正在工作。这永远是我无法解决的最愚蠢的错误。欢迎来到堆栈溢出。我很高兴这对你有帮助。如果此答案解决了您的问题,请将其标记为已接受。
//Main Class
public class Main extends Application{
Stage window;
Scene scene1,scene2;
VBox panel;
TableView<Resources> table; 

public static void main(String[] args){
    launch(args);
}

@Override
public void start(Stage stage) throws Exception {

    //Stage
    window = stage;     
    window.setTitle("Test Application - TableView");

    //TableColumns
    TableColumn<Resources, String> name_c = new TableColumn<Resources, String>("Resource Name");    
    name_c.setMinWidth(200);
    name_c.setCellValueFactory( new PropertyValueFactory<>("Name"));
    //---------------------------------------------

    TableColumn<Resources, Double> price_c = new TableColumn<Resources, Double>("Resource Price");  
    price_c.setMinWidth(125);
    price_c.setCellValueFactory( new PropertyValueFactory<>("Price"));
    //---------------------------------------------

    TableColumn<Resources, Integer> inventory_c = new TableColumn<Resources, Integer>("Resource Inventory");    
    inventory_c.setMinWidth(125);
    inventory_c.setCellValueFactory( new PropertyValueFactory<Resources, Integer>("Inventory"));

    //TableView
    table = new TableView<>();
    table.getColumns().addAll(name_c, price_c, inventory_c);
    table.setItems(getResources());

    //VBox
    panel = new VBox();
    panel.getChildren().add(table);

    // Scene
    Scene scene = new Scene(panel,500,250);
    window.setScene(scene);
    window.show();
}

public ObservableList<Resources> getResources(){
    //Inserts into the TableView the Values
    ObservableList<Resources> res = FXCollections.observableArrayList();
    res.add( new Resources("Wood", 9.99, 100));
    res.add( new Resources("Iron", 12.85, 70));
    res.add( new Resources("Cotton", 3.16, 200));
    res.add( new Resources("Marble", 20.75, 50));
    res.add( new Resources("Glass", 5.99, 175));

    return res;
}
}

//Resources Class
public class Resources {

private String name;
private double price;
private int inventory;

//Constructors
public Resources(){
    this.name = "";
    this.price = 0;
    this.inventory = 0;
}

public Resources(String n,double p,int i){
    this.name = n;
    this.price = p;
    this.inventory = i;
}

//Getters & Setters.
public String getName() {
    return name;
}

public void setName(String nm) {
    this.name = nm;
}

public double getPrice() {
    return price;
}

public void setPrice(double pr) {
    this.price = pr;
}

public int getInvetory() {
    System.out.println(inventory);//Inventory Test (Data not displaying, works with the other get functions)
    return inventory;
}

public void setInvetory(int inv) {
    this.inventory = inv;
}

}