Reputation: 80415
I am trying to connect to a SQLite database that's located in the assets folder of a project. I wrote up a class, here is the part that is throwing an error:
public class Database
{
private var sqlConnection:SQLConnection;
public function connect(db:String):Object
{
var response:Object={status:false,message:''};
try
{
var dbFile:File=File.applicationDirectory.resolvePath(db);
sqlConnection.open(dbFile);
response.status=true;
response.message='';
}
catch(error:SQLError)
{
response.status=false
response.message=error.message;
}
return response;
}
}
I call that class in an MXML view component on the creationComplete
handler:
private function init():void
{
var db:Database=new Database();
var connectResponse:Object=db.connect('assets/data.db');
if(connectResponse.status)
{
//getData() runs a simple select query and returns an array
acData=new ArrayCollection(db.getData());
}
else
{
//If the status is false I show a label control for debugging
labelError.text=connectResponse.message;
labelError.includeInLayout=true;
labelError.visible=true;
}
list.dataProvider=acData;
}
The error I get is something along the lines: TypeError: Error #1009: Cannot access a property or method of a null object reference.
.
Upvotes: 0
Views: 1017
Reputation:
I think you need to instantiate your sqlConnection before you use it:
sqlConnection = new SQLConnection();
sqlConnection.open(dbFile);
Upvotes: 1