5

I'm very new to vaadin ( and to java).

i have an table that has an SQLcontainer like so :

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

          commit();
          setSelectable(true);

      }
    }

i have a button and a TextField , to fill data in the table

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();
        }

i keep getting a " null pointer exception" no matter what i do. on the line **cont.getContainerProperty(itemId , "id").setValue(dataResult);

am i doing anything wrong ? and what is null pointer ?

please inform me if anything was unclear.

please help , thanks in advance.

4

2 回答 2

4

BTW, if you have a Vaadin Table and you applied a Filter to it, you need to remove it before, if not probably you will get a null pointer exception in the getContainerProperty(itemId, property) method

于 2013-10-08T01:20:09.450 回答
2

This expression returns null:

cont.getContainerProperty(itemId , "id")

And then you try to invoke a method on null. This causes the NullPointerException. So have a look, why the container does not provide a non-null value for the key at the time you invoke it.

于 2012-08-16T05:44:03.380 回答