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

Moa*_*ghi 5 java vaadin

我对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);

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

如果有什么不清楚的地方请通知我.

请帮助,提前谢谢.

And*_*s_D 2

该表达式返回null

cont.getContainerProperty(itemId , "id")
Run Code Online (Sandbox Code Playgroud)

然后您尝试调用 上的方法null。这会导致NullPointerException. 那么看看为什么容器在您调用它时不为键提供非空值。

  • 容器不包含项目“itemId”*或*对象“itemId”没有属性“id”。这就是返回“null”的规则。`getContainerPropertyIds` 不应返回 null,而应返回空列表(在最坏的情况下)。 (2认同)