首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >CoronaSDK控制器错误

CoronaSDK控制器错误
EN

Stack Overflow用户
提问于 2012-05-29 11:21:57
回答 1查看 1.7K关注 0票数 0

我目前正在使用CoronaSDK和Lua编写一个跨平台的应用程序。我正在使用导演包来切换场景。然而,我得到了以下错误:

“控制器错误:无法在‘启动’时执行新(参数)函数。”

我知道错误来自我的主类。这就是:

代码语言:javascript
运行
复制
-----------------------------------------------------------------------------------------
--
-- 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文件:

代码语言:javascript
运行
复制
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

下面是我在控制台中得到的错误:

代码语言:javascript
运行
复制
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
---------------
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-05-29 11:41:56

该错误是控制器类错误。它的发生是因为您的startUp.lua有一些错误。

您使用的是最新的director类(1.4)吗?最新的控制器类也显示了实际的错误。

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

编辑:

我能想到两件事。

1.尝试将director.changeScene更改为director: startUp.lua中2个位置的changeScene

2.尝试删除main.lua中的第二个本地mainGroup = display.newGroup() (尽管我怀疑这是否可行)

实际的错误

代码语言:javascript
运行
复制
-----------------------
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)
-----------------------

第二行是avtual error。

发现错误,我认为是

我认为错误是因为您没有onSystemEvent函数。通常,如果您尝试将侦听器添加到不存在的函数中,则会出现断言失败错误!

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10792710

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档