Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Runtime error on Android
Started by contact444 Jan 15 2018 08:40 AM

7 replies to this topic
android widget scrollview runtime error
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

contact444

[GLOBAL: userInfoPane.html]
contact444
  • Observer

  • 14 posts
  • Corona SDK

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


[TOPIC: post.html]
#2

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,895 posts
  • Enterprise

What version of Corona are you using?

 

Rob



[TOPIC: post.html]
#3

contact444

[GLOBAL: userInfoPane.html]
contact444
  • Observer

  • 14 posts
  • Corona SDK

That'd be 

2017.3184 (2017.12.8)



[TOPIC: post.html]
#4

agramonte

[GLOBAL: userInfoPane.html]
agramonte
  • Corona Geek

  • 1,171 posts
  • Corona SDK

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



[TOPIC: post.html]
#5

bradp904

[GLOBAL: userInfoPane.html]
bradp904
  • Observer

  • 1 posts
  • Corona SDK

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.



[TOPIC: post.html]
#6

contact444

[GLOBAL: userInfoPane.html]
contact444
  • Observer

  • 14 posts
  • Corona SDK

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. 



[TOPIC: post.html]
#7

marbenpou

[GLOBAL: userInfoPane.html]
marbenpou
  • Observer

  • 2 posts
  • Corona SDK

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



[TOPIC: post.html]
#8

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,895 posts
  • Enterprise

Try leaving the leading "/" off.  




[topic_controls]
[/topic_controls]