CoronaSDK导演错误

我目前正在使用CoronaSDK和Lua编写跨平台应用程序。我正在使用导演包来更改场景。但是,我得到了以下错误:

“Director ERROR: Failed to execute new(params) function on 'startUp'。”

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

 -----------------------------------------------------------------------------------------
 -
 - 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”

     --显示默认状态栏(iOS)
     display.setStatusBar(display.DefaultStatusBar)

     local mainGroup = display.newGroup()

     --选项卡按钮事件侦听器:
     local function onFirstView(event)
         director:changeScene(“startUp”)
     end

     local function onSecondView(event)
         director:changeScene(“home”)
     end

     --表格设置按钮
     local tabButtons = {
         {label =“主页”,up =“icon1.png”,down =“icon1-down.png”,width = 32,height = 32,onPress = onFirstView,selected = true},
         {label =“卡片”,up =“icon2.png”,down =“icon2-down.png”,width = 32,height = 32,onPress = onSecondView},
     }

     --创建实际的tabBar widget
     local tabBar = widget.newTabBar {
         top = display.contentHeight,
         buttons = tabButtons
     }

     --我认为是这行导致了错误
     director:changeScene(“startUp”)

     return true
 end

 timer.performWithDelay(3000,main,1)

这是我的startUp.lua文件:

 模块(...,package.seeall)

 function new()
     require“sqlite3”
     local director = require(“director”)
     -连接到数据库或创建它。
     -每个用户都有自己的数据库 * ***
     local path = system.pathForFile(“data.db”,system.DocumentsDirectory)
     local db = sqlite3.open(path)

     -如果数据库表不存在,则创建它
     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
         -如果用户在数据库中,则转到主页。
         director.changeScene(“home”)
     end

     -如果不在数据库中,请转到表格
     director.changeScene(“forms”)

     -捕捉应用程序退出
     Runtime:addEventListener(“system”,onSystemEvent)

     -处理应用程序退出-关闭数据库连接
     local function onSystemEvent(event)
         if(event.type ==“applicationExit”)then
             db:close()
         end
         print(“数据库已关闭”)
     end

 end

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

运行时错误director.lua:1092:尝试调用方法'insert'nil值)
堆栈跟踪:在函数'insert'中在函数'changeScene'
---------------
导演错误:未能在“startUp”上执行新的(params)函数。
---------------
断言失败
---------------
点赞
用户1137788
用户1137788

错误是关于导演类的错误。它发生是因为你的 startUp.lua 中有一些错误。

你是否使用了最新的导演类(1.4版本)?最新的导演类会显示实际的错误信息。

另外,注意到文件名区分大小写。你的文件必须是 startUp.lua 而不是startup.lua。

编辑:

我可以想到两件事。

1.尝试在 startUp.lua 的两个位置将 director.changeScene 改为 director:changeScene。

2.尝试在 main.lua 中删除第二个 local 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 错误!

2012-05-29 03:41:55