Runtime error on Android

This is an issue regarding Widget ScrollView on Android. 

I’m getting the following error on Android only - 

RUNTIME ERROR 

/User/jenkins/slaveroot/workspace/Templates/label/android/subrepos/widget/widgetLibrary/widget_scrollview.lua:464: ERROR : table expected. If this is a function call, you might have used ‘.’ instead of ‘:’

This works fine on the Simulator otherwise. 

Here’s my code - 

local composer = require(“composer”)

local widget = require(“widget”)

local scene = composer.newScene()

local splash

local baijobranding

local footballbranding

local  websitelabel 

local backbutton

local hscrollview

local buttonclick 

– Scroll pagination listener 

local function scrollViewListener(event)

if (event.phase==“ended”) then 

x,y = event.target:getContentPosition()

pageno = math.round(math.abs(x)/display.contentWidth)

event.target:scrollToPosition ({x=-1*pageno*display.contentWidth, time = 300})

end 

end

–Back button handler 

local function onKeyEvent( event )

    if (event.phase==“up” and event.keyName==“back”) then

    composer.gotoScene(“menu”, {effect=“fade”, time=300})

    end

    return true

end

–Soft button handler

local function handleButtonEvent( event )

    if ( “ended” == event.phase ) then

    if (soundon) then audio.play(buttonclick) end 

    if (event.target==backbutton) then

    --close settings 

    composer.gotoScene(“menu”, {effect=“fade”, time=300})

    end

    end

end

function scene:create(event)

local sceneGroup = self.view

buttonclick = audio.loadSound(“sounds/button-click.mp3”)

splash = display.newImage(“images/background.jpg”, display.contentCenterX, display.contentCenterY)

sceneGroup:insert(splash)

baijobranding = display.newImage(“images/baijobranding.png”, display.contentWidth*0.33, display.contentHeight*0.25)

baijobranding:scale(0.7, 0.7)

sceneGroup:insert(baijobranding)

footballbranding = display.newImage(“images/footballbranding.png”, display.contentWidth*0.66, display.contentHeight*0.25)

footballbranding:scale(0.7, 0.7)

sceneGroup:insert(footballbranding)

backbutton = widget.newButton(

    {

        width = 345,

        height = 206,

        defaultFile = “images/backbutton.png”,

        overFile = “images/backbutton.png”,

        onEvent = handleButtonEvent

    }

)

backbutton.x = display.contentWidth*0.1

backbutton.y = display.contentHeight*0.15

– local howtolabel = display.newText(“HOW TO”, display.contentWidth*0.5, display.contentHeight*0.1, “fonts/ERASDEMI.TTF”)

– howtolabel.size = 90

hscrollview = widget.newScrollView(

{

backgroundColor = {0,0,0,0} ,

hideScrollBar = true, 

x = display.contentCenterX, 

y = display.contentCenterY, 

width = display.contentWidth, 

height = display.contentHeight,

scollWidth = display.contentWidth*5,

verticalScrollDisabled = true, 

friction = 0.1,

listener = scrollViewListener

})

for i=1,5 do 

local howtoimg = display.newImage("/images/howto/howto"…i…".jpg", (display.contentWidth*(i-1)) + display.contentCenterX, display.contentCenterY)

hscrollview:insert(howtoimg)

end

sceneGroup:insert(hscrollview)

– sceneGroup:insert(howtolabel)

sceneGroup:insert(backbutton)

end

function scene:show(event)

local sceneGroup = self.view

local phase = event.phase

if (phase==“will”) then 

– scene not on screen 

elseif (phase==“did”) then 

– scene now on screen 

Runtime:addEventListener( “key”, onKeyEvent )

end

end

function scene:hide(event)

local sceneGroup = self.view

local phase = event.phase

if (phase==“will”) then 

– scene on screen 

Runtime:removeEventListener (“key”, onKeyEvent)

elseif (phase==“did”) then 

– scene not on screen 

end

end

function scene:destroy(event)

local sceneGroup = self.view

end

scene:addEventListener(“create”, scene)

scene:addEventListener(“show”, scene)

scene:addEventListener(“hide”, scene)

scene:addEventListener(“destroy”, scene)

return scene

What version of Corona are you using?

Rob

That’d be 

2017.3184 (2017.12.8)

local howtoimg = display.newImage("/images/howto/howto"..i..".jpg", (display.contentWidth\*(i-1)) + display.contentCenterX, display.contentCenterY)

Are you sure that is the correct path for that image and that the name matches exactly what is on the file system? Check to see if “howtoing” is nil.

Adrian

I had this error message on my brand new Galaxy S7. I managed to fix it by reboot my device, after reboot it and install the latest version of Android Oreo, It solved. It was surprisingly easy.

Thanks agramonte. I looked at the path and I was using  a leading ‘/’ in the images for the scrollview. 

This worked fine on the Windows simulator as the BASE PATH must be considered as the path of the main.lua file. But on Android the implementation was different and the path ‘/images/…’ must be taking it to the root path of the android device. 

Thanks again for pointing me in the right direction. 

Hi contact444 what have you written in stead of /images/ ? I am having the error coming up on android 7.0 every 10 to 20 times I run my game.

Thanks in advance

Martin

Try leaving the leading “/” off.  

What version of Corona are you using?

Rob

That’d be 

2017.3184 (2017.12.8)

local howtoimg = display.newImage("/images/howto/howto"..i..".jpg", (display.contentWidth\*(i-1)) + display.contentCenterX, display.contentCenterY)

Are you sure that is the correct path for that image and that the name matches exactly what is on the file system? Check to see if “howtoing” is nil.

Adrian

I had this error message on my brand new Galaxy S7. I managed to fix it by reboot my device, after reboot it and install the latest version of Android Oreo, It solved. It was surprisingly easy.

Thanks agramonte. I looked at the path and I was using  a leading ‘/’ in the images for the scrollview. 

This worked fine on the Windows simulator as the BASE PATH must be considered as the path of the main.lua file. But on Android the implementation was different and the path ‘/images/…’ must be taking it to the root path of the android device. 

Thanks again for pointing me in the right direction. 

Hi contact444 what have you written in stead of /images/ ? I am having the error coming up on android 7.0 every 10 to 20 times I run my game.

Thanks in advance

Martin

Try leaving the leading “/” off.