Jump to content




The least helpful debug error ever


  • You cannot reply to this topic
3 replies to this topic

#1 TheRockettek

  • Members
  • 547 posts
  • LocationRem is best girl

Posted 15 April 2016 - 08:15 PM

So i tried doing my program and when i run it, the computer just errors java.lang.ArrayIndexOutOfBoundException

Heres the program:

monitor = peripheral.wrap("right")
tz = "UTC"

function getTime(tz,format)
 time = http.get("http://therockettek.hol.es/API/Time.php?  TZ="..textutils.urlEncode(tz).."&FORMAT="..textutils.urlEncode(format)).readAll()
 if time == "" then
  time = "ERR"
 end
 return time
end

function drawBox()
 hour = getTime(tz,"G")
 if hour > 16 and hour < 5 then
   print("night")
   bx,by = monitor.getSize()
   paintutils.drawFilledBox(1,1,bx,by,colors.black) 
 else
  print("day")
  bx,by = monitor.getSize()
  paintutils.drawFilledBox(1,1,bx,by,colors.yellow)
 end
end

drawBox()

Edited by TheRockettek, 15 April 2016 - 08:16 PM.


#2 TheRockettek

  • Members
  • 547 posts
  • LocationRem is best girl

Posted 15 April 2016 - 08:21 PM

Posted Image

#3 Anavrins

  • Members
  • 775 posts

Posted 15 April 2016 - 08:32 PM

My first guess is that getTime returns a string, and you're trying to compare it with a number.
Try replacing return time into return tonumber(time)
There's also a space between php? and TZ, which might make it always error.

Edited by Anavrins, 15 April 2016 - 08:35 PM.


#4 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 15 April 2016 - 11:25 PM

The "least helpful" errors are the ones where you get nothing at all, or worse, when the script doesn't even crash...

This particular error generally shows up when you make an infinite loop of recursive function calls. Each instance of a running function goes into a Java array, and once you max out its capacity you get a crash.

However, the script you've posted doesn't do that. In fact, running it myself I get an entirely different error, based on you trying to compare a number against a string. I suspect you're not running the script you think you're running.

Another couple of points, for whatever reason attempting to get and read from a URL in one go never seems to work, and you should be retaining the handle so you can close it anyway:

local handle = http.get("http://therockettek.hol.es/API/Time.php?TZ="..textutils.urlEncode(tz).."&FORMAT="..textutils.urlEncode(format))
local time = handle.readAll()
handle.close()

... and don't forget to redirect to your wrapped monitor!





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users