Android Question Java Exception on DB operation

QtechLab

Active Member
Licensed User
Longtime User
Hi,
i'm aving some problems with an app. Sometimes comes out a Java Exception.
This esception says:
"An error occurred in sub: mdlsql_sqltableread(java line:474)
java.lang.runtimeRuntimeException: Object should first be initialized.
Continue?"

Now, i've found the function that has the line 474 in java file:
B4X:
public static anywheresoftware.b4a.sql.SQL.CursorWrapper  _sqltableread(anywheresoftware.b4a.BA _ba,anywheresoftware.b4a.sql.SQL _sqlcnn,String _fldlist,String _tbname,String _filter,String _order) throws Exception{
anywheresoftware.b4a.sql.SQL.CursorWrapper _cursor1 = null;
String _strsql = "";
//BA.debugLineNum = 9;BA.debugLine="Sub SQLTableRead(SqlCnn As SQL, FldList As String,";
//BA.debugLineNum = 16;BA.debugLine="Dim Cursor1 As Cursor";
_cursor1 = new anywheresoftware.b4a.sql.SQL.CursorWrapper();
//BA.debugLineNum = 17;BA.debugLine="Dim strSql As String";
_strsql = "";
//BA.debugLineNum = 18;BA.debugLine="If FldList = \"\" Then FldList = \"*\"";
if ((_fldlist).equals("")) {
_fldlist = "*";};
//BA.debugLineNum = 19;BA.debugLine="strSql = \"SELECT \" & FldList & \" FROM \" & TbName";
_strsql = "SELECT "+_fldlist+" FROM "+_tbname;
//BA.debugLineNum = 20;BA.debugLine="If Filter <> \"\" Then strSql = strSql & \" WHERE \"";
if ((_filter).equals("") == false) {
_strsql = _strsql+" WHERE "+_filter;};
//BA.debugLineNum = 21;BA.debugLine="If Order <> \"\" Then strSql = strSql & \" ORDER BY";
if ((_order).equals("") == false) {
_strsql = _strsql+" ORDER BY "+_order;};
//BA.debugLineNum = 23;BA.debugLine="Cursor1 = SqlCnn.ExecQuery(strSql)";
_cursor1.setObject((android.database.Cursor)(_sqlcnn.ExecQuery(_strsql)));
//BA.debugLineNum = 25;BA.debugLine="Return Cursor1";
if (true) return _cursor1;
//BA.debugLineNum = 27;BA.debugLine="End Sub";
return null;
}

This is the line 474: _cursor1.setObject((android.database.Cursor)(_sqlcnn.ExecQuery(_strsql)));

Note that when the crash happens i'm not operating with the function that throws the exception. If i do step by step debug it do not crash.

Thanks in advance,
Best Regards
 

QtechLab

Active Member
Licensed User
Longtime User
I'm initializing the SQL object on "first activity" load event, the sql object is a public variable.
 
Upvote 0

QtechLab

Active Member
Licensed User
Longtime User
Are you saying that i should use a service as "root" module to control others instead of an activity?
The SQL object and many other objects are declared in the starter activity process global sub!
 
Upvote 0
Top