2012-05-29 31 views
0

我目前正在使用CoronaSDK和Lua編寫一個跨平臺的應用程序。我正在使用導演包來改變場景。但是,我收到以下錯誤:CoronaSDK Director Error

「控制器錯誤:未能執行新的(params)功能'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" 

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

回答

1

錯誤是主任級的錯誤。它發生是因爲你的startUp.lua有一些錯誤。

你在使用最新的導演類(1.4)嗎?最新的導演類也顯示實際錯誤。

而不是該文件區分大小寫。你的文件必須是startUp.lua而不是startup.lua。

編輯:

我能想到2件事情。

1.Try改變director.changeScene導演:在2個地方changeScene在startUp.lua

2.Try去除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) 
----------------------- 

第二行是avtual錯誤。

發現錯誤,我認爲

我認爲錯誤是因爲你沒有onSystemEvent功能。 通常聲明失敗如果您嘗試將偵聽器添加到不存在的函數,則會發生錯誤!

+0

我添加了我的startUp.lua文件 - 請參閱編輯 – ewein

+0

好的!編輯了我的答案! – SatheeshJM

+0

這些更改後仍出現同樣的錯誤。 – ewein