Menu

Handling not assigned properties

Help
Dominik
2014-02-03
2014-03-19
  • Dominik

    Dominik - 2014-02-03

    Hi,

    when i try to access a property which does not exit my loop and programm stops without exception.

    Here is my code:
    for (Object o : calendar.getComponents("VEVENT")) {
    Component c = (Component)o;
    //Location is not set / does not exist
    c.getProperty("LOCATION").getValue();
    }

    How can i handle this? c.getProperty("LOCATION").isCalendarProperty() doesnt seem to return a value. It "crashes" like the getValue.

     
  • Lukas Aichbauer

    Lukas Aichbauer - 2014-03-19

    Hi!
    By the way you should use constants. And I don't think your programm stops without exception, it is a java.lang.NullPointerException.

    for (Object o : calendar.getComponents(Component.VEVENT)) {
        Component c = (Component)o;
        //Location is not set / does not exist
        Property p = c.getProperty(Property.LOCATION);
    
        //Check for null
        if(p != null) {
            String value = p.getValue();
        }    
    }
    

    Lukas

     

    Last edit: Lukas Aichbauer 2014-03-19

Log in to post a comment.