Why do I get a NullPointerException in this script? It is launched by desktop load event. The IDs are correct.

Why do I get a NullPointerException in this script? It is launched by desktop load event. The IDs are correct.

var d = LL.getHomeDesktop();

d.getItemById(116).setVisibility(false);

d.getItemById(117).setVisibility(false);

d.getItemById(118).setVisibility(false);

]]>

9 Commentsto Why do I get a NullPointerException in this script? It is launched by desktop load event. The IDs are correct.

  1. Anonymous says:

    < ![CDATA[

    I think the issue is the getHomeDesktop (you are using it well, I’m saying that maybe there is a bug with it)


    What happen if you use instead LL.getEvent().getContainer()


    or


    LL.getCurrentDesktop()


    ?

    ]]>

  2. Anonymous says:

    < ![CDATA[

    This is because the desktop is loaded, but items have not been fully initialized yet. You can access and modify their properties, but anything related to display will fail. I am working on the issue.

    ]]>

  3. Anonymous says:

    < ![CDATA[

    TrianguloY both with the same result. 


    With homedesktop and getcontainer the first item gets invisible, with currentdesktop none of them gets invisible.


    Exception is always thrown in line 2.

    ]]>

  4. Anonymous says:

    < ![CDATA[

    you can use try catch to get the error and simply try again in a millisecond with setTimeout. It’s a hack, I know.

    ]]>

  5. Anonymous says:

    < ![CDATA[

    Bogdan Tautu very strange, but it works:



    var d = LL.getHomeDesktop();


    try


    {


    d.getItemById(116).setVisibility(false);


    }


    catch(NullPointerException){}


    try


    {


    d.getItemById(117).setVisibility(false);


    }


    catch(NullPointerException){}


    try


    {


    d.getItemById(118).setVisibility(false);


    }


    catch(NullPointerException){}

    ]]>

  6. Anonymous says:

    < ![CDATA[

    it does not give error, not sure it works.

    ]]>

  7. Anonymous says:

    < ![CDATA[

    I will add a workaround for visibility but other calls may fail too. For instance getting the size of an item may not always work because it requires the item to be displayed to be known, and the android process is asynchronous, meaning that the desktop can be loaded, and displayed later, hence some things are not available at time of loading.

    ]]>

  8. Anonymous says:

    < ![CDATA[

    if setTimeout works (there was a post that said it gives an error) you can try to set and get any parameter in case of an error.


    I will try it and post to the script repository.

    ]]>

  9. Anonymous says:

    < ![CDATA[

    Fixed. First script now works.

    ]]>

Leave a Reply

Your email address will not be published. Required fields are marked *