Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vaadin, getting null pointer when trying to add item to sqlContainer

Tags:

java

vaadin

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.

like image 527
Moayyad Yaghi Avatar asked Aug 16 '12 05:08

Moayyad Yaghi


2 Answers

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

like image 121
Diego Quirós Avatar answered Sep 23 '22 04:09

Diego Quirós


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.

like image 21
Andreas Dolk Avatar answered Sep 25 '22 04:09

Andreas Dolk