【问题标题】:1067: Implicit coercion of a value of type Class to an unrelated type flash.data:SQLConnection1067:将 Class 类型的值隐式强制转换为不相关的类型 flash.data:SQLConnection
【发布时间】:2013-11-25 06:54:58
【问题描述】:

我正在尝试使用此代码为我的本地 sqlite 数据库创建新记录 但它不起作用,当我点击保存时出现此错误

1120:Access of undefined property sqlConnection.

这是我在 EmployeeDAO 中的方法

          public static function  create(employee:Employee):void
    {

    var sql:String = "INSERT INTO words (id, term, defin, term1, defin1) " +
            "VALUES (?,?,?,?,?)";
        var stmt:SQLStatement = new SQLStatement();
        stmt.sqlConnection = sqlConnection;
        stmt.text = sql;

        stmt.parameters[1] = employee.term;
        stmt.parameters[2] = employee.defin;
        stmt.parameters[3] = employee.term1;
        stmt.execute();
        employee.loaded = false;
    }

add.mxml 我尝试将记录保存到数据库的位置

    import model.Employee;
    import model.EmployeeDAO;

        protected function onSave():void {

            var newEmployee:Employee = new Employee();
            newEmployee.term = term.text;
            newEmployee.defin = defin.text;
            newEmployee.term1 = term1.text;
            newEmployee.defin1 = defin1.text;
            EmployeeDAO.create(newEmployee);
            navigator.popView();
        }
    ]]>
</fx:Script>

<s:actionContent>
    <s:Button label="Save" click="onSave()"/>
</s:actionContent>

<s:layout>
    <s:VerticalLayout paddingLeft="10" paddingRight="10" paddingTop="10" paddingBottom="10"/>
</s:layout>

<s:Label text="term"/>
<s:TextInput id="term" width="100%"/>

<s:Label text="defin"/>
<s:TextArea id="defin" width="100%" height="200"/>

<s:Label text="term1"/>
<s:TextInput id="term1" width="100%"/>

<s:Label text="defin1"/>
<s:TextArea id="defin1" width="100%" height="200"/>

【问题讨论】:

    标签: android sqlite apache-flex flash-builder


    【解决方案1】:

    如果你想在不实例化类的情况下调用它,你应该将你的函数声明为静态的。然后就可以了

    public static function  create(employee:Employee):void
    

    【讨论】:

    • 肯定会报错。根据您的代码 sqlconnection 未定义。如果您在静态函数之外定义了 sqlConnection,那么它也应该定义为静态的。
    • 但我不能多次定义它,已经做了“公共函数获取 sqlConnection():SQLConnection”
    • 定义为public static function get sqlConnection():SQLConnection
    • 它无法识别 EmployeeDAO.create(newEmployee) 中的创建函数;
    • 能否贴出你最新的代码sn-p,以便我更好地理解问题
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-06-29
    • 1970-01-01
    • 2014-08-01
    • 2011-10-19
    • 2016-09-24
    • 1970-01-01
    • 2015-12-12
    相关资源
    最近更新 更多