編輯:正在開發中使用SQLite數據庫的移動應用程序,但我沒有成功,當我運行它給我這個錯誤調試器中的程序做搜索功能柔性1061:調用可能未定義的方法findbyterm
:
1061:ArrayCollection的:通過參照 靜態類型mx.collections調用可能未定義的方法findByTerm。
這是我MAINVIEW:
<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
title="Notes">
<fx:Script>
<![CDATA[
import model.Words;
import model.WordsDatabase;
]]>
</fx:Script>
<s:actionContent>
<s:Button label="Button" />
<s:Button label="Add" click="onAddButtonClicked(event)"/>
<s:Button click="WordsDatabase.words().findbyTerm(searchKey.text)"/>
</s:actionContent>
<s:List dataProvider="{WordsDatabase.words()}" change="onWordsSelected(event)"
left="0" right="0" top="0" bottom="0">
<s:itemRenderer>
<fx:Component>
<s:IconItemRenderer labelField="term" />
</fx:Component>
</s:itemRenderer>
</s:List>
<s:TextInput id="searchKey" x="0" y="0" width="480"/>
</s:View>
模型包2點的方法,我用WordsDatabase.as
public static function findbyTerm(searchKey:String):ArrayCollection
{
var sql:String = "SELECT * FROM words WHERE term LIKE ?";
var stmt:SQLStatement = new SQLStatement();
stmt.sqlConnection = sqlConnection;
stmt.text = sql;
stmt.parameters[0] = '%' + searchKey + '%';
stmt.execute();
var result:Array = stmt.getResult().data;
if (result)
{
var wordsList:ArrayCollection = new ArrayCollection();
for (var i:int=0; i<result.length; i++)
{
wordsList.addItem(processRow(result[i]));
}
return wordsList;
}
else
{
return null;
}
}
public static function words():ArrayCollection
{
var wordsList:ArrayCollection = new ArrayCollection();
var sql:String = "SELECT id, term, defin, term1, defin1 FROM words";
var stmt:SQLStatement = new SQLStatement();
stmt.sqlConnection = sqlConnection;
stmt.text = sql;
stmt.execute();
var sqlResult:SQLResult = stmt.getResult();
if (sqlResult) {
var result:Array = sqlResult.data;
if (result) {
for (var index:Number = 0; index < result.length; index++) {wordsList.addItem(processRow(result[index]));
}
}
}
return wordsList;
}
protected static function processRow(o:Object):Words
{
var words:Words = new Words();
words.id = o.id;
words.term = o.term == null ? "" : o.term;
words.defin = o.defin == null ? "" : o.defin;
words.term1 = o.term1 == null ? "" : o.term1;
words.defin1 = o.defin1 == null ? "" : o.defin1;
return words;
}
public static function openDatabase(file:File):void
{
var newDB:Boolean = true;
if (file.exists)
newDB = false;
_sqlConnection = new SQLConnection();
_sqlConnection.open(file);
if (newDB)
{
createDatabase();
populateDatabase();
}
}
protected static function createDatabase():void
{
var sql:String =
"CREATE TABLE IF NOT EXISTS words ("+
"id INTEGER PRIMARY KEY AUTOINCREMENT, " +
"term VARCHAR(50), " +
"defin VARCHAR(250), " +
"term1 VARCHAR(50), " +
"defin1 VARCHAR(200))";
var stmt:SQLStatement = new SQLStatement();
stmt.sqlConnection = sqlConnection;
stmt.text = sql;
stmt.execute();
}
protected static function populateDatabase():void
{
var file:File = File.applicationDirectory.resolvePath("assets/words.xml");
if (!file.exists) return;
var stream:FileStream = new FileStream();
stream.open(file, FileMode.READ);
var xml:XML = XML(stream.readUTFBytes(stream.bytesAvailable));
stream.close();
for each (var n:XML in xml.words)
{
var words:Words = new Words();
words.id = n.id;
words.term = n.term;
words.defin = n.defin;
words.term1 = n.term1;
words.defin1 = n.defin1;
addWords(words);
}
}
}
}
我沒有看到您在代碼中使用「findbyTerm」方法的位置。你已經提供了很多代碼來篩選。你能整理一個簡單的例子來解釋這個問題嗎?根據您在ArrayCollection類上使用findByTerm()方法的錯誤,並且ArrayCollection類沒有該方法。 – JeffryHouser
好吧現在它可以很容易地看到,我只是不想刪除這麼多,以便足夠清楚 – sayydo
什麼是在MainView中的數據? – JeffryHouser