【发布时间】:2011-08-25 18:58:40
【问题描述】:
简单易懂的问题,希望有同样简单的解决方案:
当我输入搜索查询时,有时会在 dataField = new ArrayCollection(result.data); 行中收到“错误 #1009 无法访问空对象引用的属性或方法”。
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) 使用 Array 而不是 ArrayCollection(我发现有人在某个论坛上的某个论坛上发现这对他们的项目有用)
4) 添加一个计时器函数来尝试限制搜索数据库的频率。 (虽然我认为这是最好的解决方案,但我想我必须再试一次)
请注意,据我所知,错误的发生主要是由于输入搜索字符太快
感谢您的帮助。
【问题讨论】:
标签: apache-flex sqlite