This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
orik1997's profile picture

java Exeption Thrown:

Started by orik1997, 01 May 2015 - 01:44 PM
orik1997 #1
Posted 01 May 2015 - 03:44 PM
Hi guys I have been running this script as a startup for a long time:
http://pastebin.com/UVJ46frp
Now all of a sudden I have gotten the error:
Java Exception Thrown:
java.lang.UnsupportedOperationException

I have recently added Peripheralls ++ to my Computercraft is this a problem in my code or is it with the game this has popped up on other scripts as well.
KingofGamesYami #2
Posted 01 May 2015 - 04:09 PM
The only part I can see that might cause problems is this:

    local file = fs.open(harvestedFile,"a")
    file.close()

…Because you open a file, then close it without doing anything. I doubt it'd cause an error though.

Considering this happens with other scripts, I'd guess it's a problem with Peripherals++
Bomb Bloke #3
Posted 02 May 2015 - 12:37 AM
In fact, you could replace this whole block:

	harvested = {}
	local file = fs.open(harvestedFile,"a")
	file.close()
	local file = fs.open(harvestedFile,"r")
	local line = file.readLine()
	repeat
		table.insert(harvested,line)
	until line == nil
	file.close()
	x = harvested[1] + 1
	local file = fs.open(harvestedFile,"w")
	file.writeLine(x)
	file.close()
	print(x)

… with:

	local x = 1
	
	if fs.exists(harvestedFile) then
		local file = fs.open(harvestedFile,"r")
		x = tonumber(file.readLine()) + 1
		file.close()
	end
	
	local file = fs.open(harvestedFile,"w")
	file.writeLine(x)
	file.close()
	print(x)

You'd also want to make the turtle sleep on a regular basis. Currently it sleeps for five seconds if it decides it's harvest time, or if it decides it's planting time; while the crop is growing, it never sleeps, instead spamming turtle.inspect() as fast as it can.

It is possible that the error stems from your attempt to perform addition with a string. Lua usually lets you get away with that, but who knows.

You could always spread print statements throughout your script in order to figure out the exact line triggering the error.

Exactly what are you trying to turtle.inspect()?