Runtime Error on Android Device

Hi!  I’m fairly new at coding and have been working on a simple ebook style app in the simulator.  All was running well but I wanted the text to scroll so I tried to add a textBox.  In order to see if it worked i had to build for Android and load it onto my phone… except I cant get it to even reach the screen with the textBox I get snagged up on the title page with a runtime error.  error on line 36, it’s an upvalue error on my background (a nil value).  So i checked google changed local to global forward declarations, changed them back checked my file names were correct etc…  Then I just commented out line 36 and the few that followed which were only anchor points to center my image on the screen.  Now I get this error; line 47, table expected.  If this is a function call, you might have used ‘.’ instead of ‘:’  Please help!!

This is the original code which works fine in the simulator:

local composer = require( “composer” )

local scene = composer.newScene()

display.setDefault(“background”, 255,255,255)


– forward declaration

local background;

– Touch listener function for background object

local function onBackgroundTouch( self, event )

if event.phase == “ended” or event.phase == “cancelled” then

– go to page1.lua scene

composer.gotoScene( “tbContents”, “slideLeft”, 800 )

return true – indicates successful touch

end

end

function scene:create( event )

local sceneGroup = self.view

– Called when the scene’s view does not exist.

– 

– INSERT code here to initialize the scene

– e.g. add display objects to ‘sceneGroup’, add touch listeners, etc.

– display a background image

background = display.newImageRect(“Pictures/TiVaLogo.png”, display.contentWidth, display.contentHeight )

background.anchorX = 0

background.anchorY = 0

background.x = 0 

background.y = 0

– Add more text

local pageText = display.newText( “[Touch screen to continue]”, 0, 0, native.systemFont, 18 )

pageText.x = display.contentWidth * 0.5

pageText.y = display.contentHeight - (display.contentHeight*0.1)

– all display objects must be inserted into group

sceneGroup:insert( background )

sceneGroup:insert( pageText )

end

function scene:show( event )

local sceneGroup = self.view

local phase = event.phase

if phase == “will” then

– Called when the scene is still off screen and is about to move on screen

elseif phase == “did” then

– Called when the scene is now on screen

– 

– INSERT code here to make the scene come alive

– e.g. start timers, begin animation, play audio, etc.

background.touch = onBackgroundTouch

background:addEventListener( “touch”, background )

end

end

function scene:hide( event )

local sceneGroup = self.view

local phase = event.phase

if event.phase == “will” then

– Called when the scene is on screen and is about to move off screen

– INSERT code here to pause the scene

– e.g. stop timers, stop animation, unload sounds, etc.)

– remove event listener from background

background:removeEventListener( “touch”, background )

elseif phase == “did” then

– Called when the scene is now off screen

end

end

Hi @connie.gray1,

Please post specifically what the line is which is causing the error (47?). We can’t be sure if the block of code you posted matches what the actual line numbers are.

Thanks,

Brent

Line 36:

background.anchorX = 0

background.anchorY = 0

background.x = 0 

background.y = 0

 

and after I commented out these four lines I got error on line 47:

sceneGroup:insert( background )

 

Thank you.

background = display.newImageRect(“Pictures/TiVaLogo.png”, display.contentWidth, display.contentHeight )

The error suggests that it can’t find “Pictures/TiVaLogo.png”.  The simulators are not case sensitive (due to OS limitations), but the devices are case sensitive.   Make sure the case matches what’s actually in the App bundle.

Rob

I have changed the file names, copies and pasted the names, and even changed from png to jpg.  None of these worked.  I tried bypassing my title page file and going directly to the second page and received a similar error from the first line of code with a image file in it.  I’m really not sure what detail I’m missing but I am thinking it is something standard, I designed each page from the composer template available from corona, I am lost.  Please let me know if there is more info I can provide.

Thank you.

I figured out that it was something in my build file!  I will figure out what and post here for future lookers.  For now I took a Corona demo tested it on my phone and when it worked I started comparing line for line my code.  Eventually I copied and pasted the entire build file from the sample and my files worked!

Hi @connie.gray1,

Please post specifically what the line is which is causing the error (47?). We can’t be sure if the block of code you posted matches what the actual line numbers are.

Thanks,

Brent

Line 36:

background.anchorX = 0

background.anchorY = 0

background.x = 0 

background.y = 0

 

and after I commented out these four lines I got error on line 47:

sceneGroup:insert( background )

 

Thank you.

background = display.newImageRect(“Pictures/TiVaLogo.png”, display.contentWidth, display.contentHeight )

The error suggests that it can’t find “Pictures/TiVaLogo.png”.  The simulators are not case sensitive (due to OS limitations), but the devices are case sensitive.   Make sure the case matches what’s actually in the App bundle.

Rob

I have changed the file names, copies and pasted the names, and even changed from png to jpg.  None of these worked.  I tried bypassing my title page file and going directly to the second page and received a similar error from the first line of code with a image file in it.  I’m really not sure what detail I’m missing but I am thinking it is something standard, I designed each page from the composer template available from corona, I am lost.  Please let me know if there is more info I can provide.

Thank you.

I figured out that it was something in my build file!  I will figure out what and post here for future lookers.  For now I took a Corona demo tested it on my phone and when it worked I started comparing line for line my code.  Eventually I copied and pasted the entire build file from the sample and my files worked!