gpt4 book ai didi

java - vaadin,尝试将项目添加到 sqlContainer 时获取空指针

转载 作者:搜寻专家 更新时间:2023-10-31 19:57:00 25 4
gpt4 key购买 nike

我是 vaadin(和 java)的新手。

我有一个像这样的 SQLcontainer 表:

public class ProjectTable extends Table {
public ProjectTable(final DocumentmanagerApplication app) {
setSizeFull();
setContainerDataSource(app.getDbHelp().getProjectContainer());
setImmediate(true);

commit();
setSelectable(true);

}
}

我有一个按钮和一个 TextField ,用于在表格中填充数据

public void buttonClick(ClickEvent event)
{
SQLContainer cont = h.getAssetContainer();
String dataResult = tf.getValue().toString(); // TEXT FIELD
System.out.println(dataResult);






Object itemId = cont.addItem(); // cont is the container
**cont.getContainerProperty(itemId , "id").setValue(dataResult); // BUG IS HERE !!! **


try {
cont.commit();
} catch (UnsupportedOperationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

无论我做什么,我都会收到“空指针异常”。在行 **cont.getContainerProperty(itemId , "id").setValue(dataResult);

我做错了什么吗?什么是空指针?

如有不明之处请告知。

请帮助,在此先感谢。

最佳答案

顺便说一句,如果您有一个 Vaadin 表并对其应用了过滤器,则需要先将其删除,否则可能会在 getContainerProperty(itemId, property) 方法中出现空指针异常

关于java - vaadin,尝试将项目添加到 sqlContainer 时获取空指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11981238/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com