我对vaadin(和java)很新.
我有一个像这样的SQL容器的表:
public class ProjectTable extends Table {
public ProjectTable(final DocumentmanagerApplication app) {
setSizeFull();
setContainerDataSource(app.getDbHelp().getProjectContainer());
setImmediate(true);
commit();
setSelectable(true);
}
}
Run Code Online (Sandbox Code Playgroud)
我有一个按钮和一个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();
}
Run Code Online (Sandbox Code Playgroud)
无论我做什么,我都会得到一个"空指针异常".在行**cont.getContainerProperty(itemId,"id").setValue(dataResult);
我做错了什么?什么是空指针?
如果有什么不清楚的地方请通知我.
请帮助,提前谢谢.
该表达式返回null:
cont.getContainerProperty(itemId , "id")
Run Code Online (Sandbox Code Playgroud)
然后您尝试调用 上的方法null。这会导致NullPointerException. 那么看看为什么容器在您调用它时不为键提供非空值。