我是 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/