World.getObject(id) issue

Started by voronwe13, September 10, 2014, 07:24:53 PM

Previous topic - Next topic

voronwe13

I'm having an issue where I need to check if a world has a specific object in it, or whether it has been removed from the world.   Essentially, I'm doing:

if(world.getObject(object.getID()) == null){
   world.addObject(object);
}


The problem I'm having is that instead of returning null, the app is erroring out with the following message:

java.lang.RuntimeException: [ 1410369008776 ] - ERROR: Can't retrieve object #6!


at the line where I call world.getObject(object.getID());

Am I doing something wrong?

EgonOlsen

No, that's the way it's supposed to behave if the object can't be found. You can wrap it in a try-catch or, which would be more performance friendly, change the Logger's on error behaviour at for that part of the code.

voronwe13

Okay, wasn't expecting that based on the documentation.  It works now that I've set the Logger appropriately at that section of code.   Thanks!

EgonOlsen

I see. The documentation is from a time where the default error behaviour was different. I'll update the docs, thanks for mentioning it.