Error: attempt to index global after recalling text with JSON

This works well in corona simulator but doesn’t want to work on android device. What really confuses me is that it keeps saying global is nil, but my next if/then statement is also specific for a nil return, but it still comes up with an error. I’ve tried a handful of solutions but I’ll try them again if needed. Thanks in advance

[lua]

Group = {

Value = “”,

Input1 = “”

for k, v in pairs( Group ) do

   print (k, v)

end 

(NOTE: for the above, terminal reads:

Input1

Value

)

print (“Before loading Group.Value :(”…Group.Value…")")

(NOTE: for above, it reads “Before loading Group.Value :()”  )

for k, v in pairs( Group ) do

   print (k, v)

end 

(NOTE: for the above, terminal reads:

Input1

Value

)

print ("**********")

Group = loadTable(“Group.json”)

print ("here "… Group.Input1)

(NOTE: ERROR happens here. Terminal reads, Lua Runtime Error: lua_pcall failed with status: 2, error message is: …sktop/App/main.lua:46: attempt to index global ‘Group’ (a nil value)

Also when I put in the pairs (Group) lines, I get the error reading 

Lua Runtime Error: lua_pcall failed with status: 2, error message is: …sktop/App/main.lua:947: bad argument #1 to ‘pairs’ (table expected, got nil)

)

print ("here "…Group.Value)

if (Group.Value == nil ) then -----------> (if I take out the above error lines, it gets stuck here next with an error)

Value = 10

elseif (Group.Value ~= nil ) then

Value = Group.Value

end 

–end [/lua]

Line 35

Group = loadTable(“Group.json”)

loadTable is returning nil so the Group variable itself is now nil. You can’t access any properties of a nil variable so when you try to access Group.Input1 you will get the error you are seeing.

I don’t see the declaration for loadTable, but assuming the code for that function actually works, you should check that the casing for the name of “Group.json” is correct. On the simulator it usually doesn’t matter, but if the file on the device is actually " g roup.json" then you might get errors.

 If anyone has this problem, this was the important part. I mediated this error by checking if the group itself was nil. If yes, then I made the table with the default values. If not nil, then I can access the properties of the table such as Group.input1. Thanks Vince

Line 35

Group = loadTable(“Group.json”)

loadTable is returning nil so the Group variable itself is now nil. You can’t access any properties of a nil variable so when you try to access Group.Input1 you will get the error you are seeing.

I don’t see the declaration for loadTable, but assuming the code for that function actually works, you should check that the casing for the name of “Group.json” is correct. On the simulator it usually doesn’t matter, but if the file on the device is actually " g roup.json" then you might get errors.

 If anyone has this problem, this was the important part. I mediated this error by checking if the group itself was nil. If yes, then I made the table with the default values. If not nil, then I can access the properties of the table such as Group.input1. Thanks Vince