簡單地理解問題,希望能爲同樣簡單的解決方案:搜索功能投擲的錯誤#1009 - 空對象引用
當我在搜索查詢中輸入,我有時會收到「錯誤#1009無法訪問的屬性或方法在dataField = new ArrayCollection(result.data);
行上的「空對象引用」。
AS3:
private function getSearch():void
{
//status = "Loading data";
selectStmt = new SQLStatement();
selectStmt.sqlConnection = conn;
var sql:String = "SELECT [Index], Title, CAST(Picture AS ByteArray) AS Picture FROM Data WHERE Title LIKE @searchTarget";
selectStmt.parameters["@searchTarget"] = "%" + searchTarget + "%";
selectStmt.text = sql;
selectStmt.addEventListener(SQLEvent.RESULT, selectResult2);
selectStmt.addEventListener(SQLErrorEvent.ERROR, selectError);
selectStmt.execute();
targetRecordId = pngIndex;
}
private function selectResult2(event:SQLEvent):void
{
//status = "Data loaded";
selectStmt.removeEventListener(SQLEvent.RESULT, selectResult);
selectStmt.removeEventListener(SQLErrorEvent.ERROR, selectError);
var result:SQLResult = selectStmt.getResult();
dataField = new ArrayCollection(result.data);
if (result.data != null) {
pngIndex = result.data.Index;
pngTitle = result.data.Title;
pngByteArray = result.data.Picture;
targetRecordId = pngIndex;
}
}
MXML:
<s:List id="myList"
x="0" y="40"
width="100%" height="100%"
labelField="Title"
dataProvider="{dataField}"
change="myList_changeHandler(event)"
>
</s:List>
事情我已經嘗試過(包括這些解決方案的排列):
1)移動的錯誤代碼SelectResult2方法中
2)添加if (result.data == null)
方法
3)使用數組,而不是ArrayCollection的(我發現有人誰發現這個地方工作了他們的項目在一些論壇)
4)添加定時器功能,試圖限制多久分貝就會得到搜索。 (雖然我認爲這是最好的解決辦法,我想我會再次嘗試這個)
注,發生了錯誤,從我可以告訴,這主要是由於輸入搜索字符的結果太快
謝謝你的幫助。
感謝您的信息 - 很高興知道正確的解決方案。 – SQLiteNoob