【问题标题】:CoronaSDK Director ErrorCoronaSDK 导向器错误
【发布时间】:2012-06-03 07:07:09
【问题描述】:

我目前正在使用 CoronaSDK 和 Lua 编写一个跨平台应用程序。我正在使用director包来改变场景。但是我收到以下错误:

“Director 错误:在 'startUp' 上执行 new(params) 函数失败。”

我知道错误来自我的主课。即:

-----------------------------------------------------------------------------------------
--
-- main.lua
--
-----------------------------------------------------------------------------------------

local director = require("director")
local mainGroup = display.newGroup()
splash = display.newImage("images/logo.png")

local main = function()

    splash:removeSelf()
    splash = nil
    mainGroup:insert(director.directorView)
    local widget = require "widget"

    -- show default status bar (iOS)
    display.setStatusBar(display.DefaultStatusBar)

    local mainGroup = display.newGroup()

    -- event listeners for tab buttons:
    local function onFirstView( event )
        director:changeScene("startUp")
    end

    local function onSecondView( event )
        director:changeScene("home")
    end

    -- table to setup buttons
    local tabButtons = {
        { label="Home", up="icon1.png", down="icon1-down.png", width = 32, height = 32, onPress=onFirstView, selected=true },
        { label="Cards", up="icon2.png", down="icon2-down.png", width = 32, height = 32, onPress=onSecondView },
    }

    -- create the actual tabBar widget
    local tabBar = widget.newTabBar{
        top = display.contentHeight,
        buttons = tabButtons
    }

    --I think it is this line which is causing the error
    director:changeScene("startUp")

    return true
end

timer.performWithDelay(3000, main, 1)

这是我的 startUp.lua 文件:

module(..., package.seeall)

function new()
    require "sqlite3"
    local director = require("director")
    --Connect to database or create it.
    --Each user gets there own database****
    local path = system.pathForFile("data.db", system.DocumentsDirectory)
    local db = sqlite3.open(path)

    --Create the database table if it does not already exist
    local tablesetup = [[CREATE TABLE IF NOT EXISTS User (id Integer autoincrement PRIMARY KEY, firstname, lastname);]]
    db:exec(tablesetup)

    for row in db:nrows("SELECT * FROM User") do
        --goto home if the user is in the database.
        director.changeScene("home")
    end

    --If not in the database go to forms
    director.changeScene("forms")

    --Catch application Exit
    Runtime:addEventListener("system", onSystemEvent)

    --Handle application exit - close the database connection
    local function onSystemEvent(event)
        if(event.type == "applicationExit") then
            db:close()
        end
        print("database closed")
    end

end

这是我在控制台中遇到的错误:

Runtime Error director.lua:1092:attempt to call method 'insert' (a nil value) 
stack traceback: in function 'insert' in function 'changeScene'
---------------
Director Error: Failed to execute new(params) function on 'startUp'.
---------------
assertion failed
---------------

【问题讨论】:

    标签: lua coronasdk


    【解决方案1】:

    该错误是导演类错误。发生它是因为您的 startUp.lua 有一些错误。

    您使用的是最新的导演类(1.4)吗?最新的导演类也显示了 ACTUAL ERROR。

    并不是说文件区分大小写。您的文件必须是 startUp.lua 而不是 startup.lua。

    编辑:

    我能想到两件事。

    1.尝试将startUp.lua中2处的director.changeScene改为director:changeScene

    2.尝试删除 main.lua 中的第二个本地 mainGroup = display.newGroup() (虽然我怀疑这会是问题)

    实际错误

    -----------------------
    Director ERROR: Failed to execute new( params ) function on 'wifiscreen'.
    -----------------------
    e:\corona\satheesh\doodle2\wifiscreen.lua:231: attempt to index global 'x' (a nil value)
    -----------------------
    

    第二行是实际错误。

    发现我认为的错误

    我认为错误是因为您没有 onSystemEvent 函数。 如果您尝试将侦听器添加到不存在的函数,通常会发生 assertion failed 错误!

    【讨论】:

    • 你得到实际的错误了吗?就像我刚刚在我的答案中更新的那个。 Director 1.4 给出了实际错误
    • 是的,解决了问题,我只需要更改它们的执行顺序。谢谢
    猜你喜欢
    • 2023-04-06
    • 1970-01-01
    • 2014-08-25
    • 1970-01-01
    • 2019-08-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多