Results 1 to 6 of 6
- 09-17-2011, 12:37 AM #1
Null-Object returned though returned object is working
Background: I have an ArrayList of Zones. The method getZoneByCoords takes the position on x and z axis as parameters, then iterates through every Zone in the List, and if the Zone's coords and the parameters match, then Zone.toString is logged and the Zone is returned,
Here is the code:
Method:
This object receives the returned Zone:Java Code:public static Zone getWhiteZoneByCoords(int x, int z) { for (int i = 0; i < whiteZones.size(); i++) { int xPos = whiteZones.get(i).x1 + 10; int zPos = whiteZones.get(i).z1 + 10; if (xPos == x && zPos == z) { MsgTools.log("ZoneCenter: " + xPos + ", " + zPos); MsgTools.log("Sending zone: " + whiteZones.get(i)); return whiteZones.get(i); } } return null; }
And this is the output:Java Code:Zone zone = ZoneManager.getWhiteZoneByCoords(evt.getBlock().getX(), evt.getBlock().getZ()); MsgTools.log("Received zone: " + zone);
Does anyone know why/how to fix this?Java Code:16:43:19 [INFORMATION] [BlackAndWhite] ZoneCorners: 1129, 1149, -358, -338 16:43:19 [INFORMATION] [BlackAndWhite] ZoneCenter: 1139, -348 16:43:19 [INFORMATION] [BlackAndWhite] Sending zone: de.boreeas.blackandwhite.ma in.Zone@14a0173 16:43:19 [INFORMATION] [BlackAndWhite] Received zone: null
Thanks
Boreeas
- 09-17-2011, 12:42 AM #2
Re: Null-Object returned though returned object is working
It's because you return a null at the end.
Also add to check if
if(xPos == x && zPos == z)
gets done.Last edited by PhQ; 09-17-2011 at 12:44 AM.
- 09-17-2011, 12:51 AM #3
Re: Null-Object returned though returned object is working
According the the output it does: The logging happens inside the if-statement, so that branch executes.
- 09-17-2011, 01:20 AM #4
- 09-17-2011, 01:32 AM #5
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,609
- Rep Power
- 5
Re: Null-Object returned though returned object is working
There does not seem to be anything in the code code you posted that would result in the log you posted (although I wonder where the log for "Zone Corners" comes from?). Perhaps post more code/log or an SSCCE that demonstrates the problem.
-
Re: Null-Object returned though returned object is working
Are you sure that the code you're showing us is the code that's running? I suggest that for better help, you consider creating and posting an SSCCE.
Similar Threads
-
value returned is zero when it is not
By gedas in forum New To JavaReplies: 21Last Post: 03-27-2011, 07:23 PM -
get url returned by search
By avizana in forum NetworkingReplies: 2Last Post: 03-14-2011, 07:43 PM -
SplashScreen.getSplashScreen() returned null
By kmm1977 in forum AWT / SwingReplies: 4Last Post: 06-21-2010, 11:04 AM -
SplashScreen.getSplashScreen() returned null
By ibrahimyoussof in forum AWT / SwingReplies: 2Last Post: 04-17-2010, 02:51 PM -
Cant we have two values returned from a method in a class
By jaiminparikh in forum Advanced JavaReplies: 7Last Post: 03-21-2009, 03:20 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks