widget error

Why did I get this error in my phone:

RUNTIME ERROR

/Users/jenkins/slaveroot/workspace/Templates/label/android/subrepos/widget/widgetLibrary/widget_button. lua 595: attempt to index local ‘view’ ( a nil value)

Can you post your widget.newButton() code?

I suspect you may be trying to create an image button and you are not passing a valid image name to widget.newButton().  If it works in the Corona Simulator, but not on device, then perhaps you have a case sensitivity issue.  Filenames in Windows and OS-X are not case sensitive where they are on Android and iOS.

Rob

[lua]

_H = display.viewableContentHeight;

_W = display.viewableContentWidth;

local widget = require (“widget”);

local composer = require (“composer”);

local scene = composer.newScene();

local procedure , startButton

function scene:create(event)

local sceneGroup = self.view

local startButtonPressed = function(event)

composer.gotoScene(“scripts.quiz.quiz1”,“slideDown”, 400)

end

local startButton = widget.newButton

{

defaultFile = “quiz/startButton.png”,

onPress= startButtonPressed,

}

procedure= display.newImage (“Quiz/quizProcedure.png”);

procedure.xScale= 1.5;

procedure.yScale= 1.5;

procedure.x= _W - 160;

procedure.y = _H - 240;

startButton.xScale = 1.5;

startButton.yScale = 1.5;

startButton.x = _W - 150;

startButton.y = _H - 50;

sceneGroup:insert(procedure);

sceneGroup:insert(startButton);

end

function scene:destroy (event)

end

scene:addEventListener(“create”, scene)

scene:addEventListener(“destroy”, scene)

return scene

[/lua]

Does the image:  quiz/startButton.png   actually exist?

Is it really named startButton.png and not startbutton.png or startButton.PNG or some other combination?

Getting the exact same issue as well here, definitely not a case sensitivity issue as I double checked the code and also renamed the files so they wouldn’t interfere with functions named in a similar fashion. 

display.setDefault( "background", 255, 255, 255 ) widget = require ("widget") local neverGiveup = audio.loadStream( "NGU.mp3" ) local function musicplay ( event ) if ("event == end.phase") then local playmusic = audio.play( neverGiveup ) end end local startbutton = widget.newButton { width = 190, height = 190, defaultFile = "startButton.png", overFile = "startButtonPressed.png", onEvent = musicplay, } startbutton.x = display.contentCenterX startbutton.y = display.contentCenterY

Can you copy/pasted the exact error you’re getting?   The error at the top appears to be from the poster using the open source version of the widget library, but more specifically that error happens if the default file fails to load.  Are these files in the folder with main.lua or are they in a sub directory?

Rob

These files are located along side main.lua and not in a sub folder, the app runs fine on the simulator, but not on my device. 

The error I get is also 

RUNTIME ERROR

/Users/jenkins/slaveroot/workspace/Templates/label/android/subrepos/widget/widgetLibrary/widget_button. lua 595: attempt to index local ‘view’ (a nil value)

I’ve tried running the app on both my Nexus 5 and Moto X (2014) both return the same error.  

There should be a stack trace that goes with it in your console log.  Can you provide a directory listing of the files?

Rob

Here’s what is returned in the console while running the app, is it possible that the issue occurs when building the app and that the images are not included? Because when building the only items excluded are the default app icons…

C:\Program Files (x86)\Minimal ADB and Fastboot>adb logcat Corona:v *:s

* daemon not running. starting it now on port 5037 *

* daemon started successfully *

  • waiting for device -

--------- beginning of crash

--------- beginning of system

--------- beginning of main

V/Corona  (21693): > Class.forName: network.LuaLoader

V/Corona  (21693): < Class.forName: network.LuaLoader

V/Corona  (21693): Loading via reflection: network.LuaLoader

I/Corona  (21693): Platform: XT1095 / ARM Neon / 5.0 / Adreno ™ 330 / OpenGL

ES 3.0 V@84.0 AU@04.04.02.162.107 (CL@) / 2014.2511

V/Corona  (21693): > Class.forName: CoronaProvider.licensing.google.LuaLoader

V/Corona  (21693): < Class.forName: CoronaProvider.licensing.google.LuaLoader

V/Corona  (21693): Loading via reflection: CoronaProvider.licensing.google.LuaLo

ader

V/Corona  (21693): WARNING: Asset file “startButton.png” does not exist.

I/Corona  (21693): Warning: /Users/jenkins/slaveroot/workspace/Templates/label/a

ndroid/subrepos/widget/widgetLibrary/widget_button.lua:571: Failed to find image

 ‘startButton.png’

V/Corona  (21693): WARNING: Asset file “startButtonPressed.png” does not exist.

I/Corona  (21693): Warning: /Users/jenkins/slaveroot/workspace/Templates/label/a

ndroid/subrepos/widget/widgetLibrary/widget_button.lua:578: Failed to find image

 ‘startButtonPressed.png’

I/Corona  (21693): Runtime error

I/Corona  (21693): /Users/jenkins/slaveroot/workspace/Templates/label/android/su

brepos/widget/widgetLibrary/widget_button.lua:595: attempt to index local ‘view’

 (a nil value)

I/Corona  (21693): stack traceback:

I/Corona  (21693):      /Users/jenkins/slaveroot/workspace/Templates/label/andro

id/subrepos/widget/widgetLibrary/widget_button.lua:595: in function 'createUsing

ImageFiles’

I/Corona  (21693):      /Users/jenkins/slaveroot/workspace/Templates/label/andro

id/subrepos/widget/widgetLibrary/widget_button.lua:1707: in function </Users/jen

kins/slaveroot/workspace/Templates/label/android/subrepos/widget/widgetLibrary/w

idget_button.lua:1512>

I/Corona  (21693):      (tail call): ?

I/Corona  (21693):      /Users/jenkins/slaveroot/workspace/Templates/label/andro

id/subrepos/widget/widgetLibrary/widget.lua:135: in function </Users/jenkins/sla

veroot/workspace/Templates/label/android/subrepos/widget/widgetLibrary/widget.lu

a:122>

I/Corona  (21693):      (tail call): ?

I/Corona  (21693):      C:\Users\Samarth Desai\Documents\Corona Projects\messing

\main.lua:14: in main chunk

V/Corona  (21693): WARNING: Asset file “startButton.png” does not exist.

I/Corona  (21693): Warning: /Users/jenkins/slaveroot/workspace/Templates/label/a

ndroid/subrepos/widget/widgetLibrary/widget_button.lua:571: Failed to find image

 'startButton.png’

V/Corona  (21693): WARNING: Asset file “startButtonPressed.png” does not exist.

I/Corona  (21693): Warning: /Users/jenkins/slaveroot/workspace/Templates/label/a

ndroid/subrepos/widget/widgetLibrary/widget_button.lua:578: Failed to find image

 'startButtonPressed.png’

It’s possible to exclude files in you build.settings.  Can you produce a list of the files in the folder with your main.lua?   Also post your build.settigns.

Rob

build.settings

config.lua

default-568h@2x.png

all the default app icons

main.lua

NGU.mp3

startButton.png

startButtonPressed.png 

all of these files are inside the root folder of the app 

settings = { orientation = { default = "portrait", supported = { "portrait", } }, excludeFiles = { iphone = { "Icon-\*dpi.png", }, android = { "Icon.png", "Icon-Small-\*.png", "Icon\*@2x.png", }, }, -- -- iOS Section -- iphone = { plist = { UIStatusBarHidden = false, UIPrerenderedIcon = true, -- set to false for "shine" overlay --UIApplicationExitsOnSuspend = true, -- uncomment to quit app on suspend CFBundleIconFiles = { "Icon.png", "Icon@2x.png", "Icon-60.png", "Icon-60@2x.png", "Icon-60@3x.png", "Icon-72.png", "Icon-72@2x.png", "Icon-76.png", "Icon-76@2x.png", "Icon-Small.png", "Icon-Small@2x.png", "Icon-Small@3x.png", "Icon-Small-40.png", "Icon-Small-40@2x.png", "Icon-Small-50.png", "Icon-Small-50@2x.png", }, --[[-- iOS app URL schemes: CFBundleURLTypes = { { CFBundleURLSchemes = { "fbXXXXXXXXX", -- replace XXXXXXXXX with your Facebook appId } } } --]] } }, -- -- Android Section -- android = { usesPermissions = { "android.permission.INTERNET", }, }, }

The build.settings was left untouched

Hi @sdesai191,

Can you post the code for your config.lua file? Are you using dynamic image selection via suffixes, i.e. @2x and/or @4x?

Thanks,

Brent

Also try leaving the excludeFiles section of your build.settings out.

Rob

I believe the issue may lie within image size (although I doubt it) , running another app that I made with the exact same build.settings and config.lua the other app runs fine. the only difference lies within this app’s images sizes. With the working one having 300 x 300 pngs while this one uses larger 400 x 400 pngs. Plus I didn’t use any @2x/4x suffixes with either app

Can you post your widget.newButton() code?

I suspect you may be trying to create an image button and you are not passing a valid image name to widget.newButton().  If it works in the Corona Simulator, but not on device, then perhaps you have a case sensitivity issue.  Filenames in Windows and OS-X are not case sensitive where they are on Android and iOS.

Rob

[lua]

_H = display.viewableContentHeight;

_W = display.viewableContentWidth;

local widget = require (“widget”);

local composer = require (“composer”);

local scene = composer.newScene();

local procedure , startButton

function scene:create(event)

local sceneGroup = self.view

local startButtonPressed = function(event)

composer.gotoScene(“scripts.quiz.quiz1”,“slideDown”, 400)

end

local startButton = widget.newButton

{

defaultFile = “quiz/startButton.png”,

onPress= startButtonPressed,

}

procedure= display.newImage (“Quiz/quizProcedure.png”);

procedure.xScale= 1.5;

procedure.yScale= 1.5;

procedure.x= _W - 160;

procedure.y = _H - 240;

startButton.xScale = 1.5;

startButton.yScale = 1.5;

startButton.x = _W - 150;

startButton.y = _H - 50;

sceneGroup:insert(procedure);

sceneGroup:insert(startButton);

end

function scene:destroy (event)

end

scene:addEventListener(“create”, scene)

scene:addEventListener(“destroy”, scene)

return scene

[/lua]

Does the image:  quiz/startButton.png   actually exist?

Is it really named startButton.png and not startbutton.png or startButton.PNG or some other combination?

Getting the exact same issue as well here, definitely not a case sensitivity issue as I double checked the code and also renamed the files so they wouldn’t interfere with functions named in a similar fashion. 

display.setDefault( "background", 255, 255, 255 ) widget = require ("widget") local neverGiveup = audio.loadStream( "NGU.mp3" ) local function musicplay ( event ) if ("event == end.phase") then local playmusic = audio.play( neverGiveup ) end end local startbutton = widget.newButton { width = 190, height = 190, defaultFile = "startButton.png", overFile = "startButtonPressed.png", onEvent = musicplay, } startbutton.x = display.contentCenterX startbutton.y = display.contentCenterY

Can you copy/pasted the exact error you’re getting?   The error at the top appears to be from the poster using the open source version of the widget library, but more specifically that error happens if the default file fails to load.  Are these files in the folder with main.lua or are they in a sub directory?

Rob

These files are located along side main.lua and not in a sub folder, the app runs fine on the simulator, but not on my device. 

The error I get is also 

RUNTIME ERROR

/Users/jenkins/slaveroot/workspace/Templates/label/android/subrepos/widget/widgetLibrary/widget_button. lua 595: attempt to index local ‘view’ (a nil value)

I’ve tried running the app on both my Nexus 5 and Moto X (2014) both return the same error.