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);
]]>
< ![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()
?
]]>
< ![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.
]]>
< ![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.
]]>
< ![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.
]]>
< ![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){}
]]>
< ![CDATA[
it does not give error, not sure it works.
]]>
< ![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.
]]>
< ![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.
]]>
< ![CDATA[
Fixed. First script now works.
]]>