New to both Android development and Java, trying to separate my queries into query / command files which inherit from a database managing QueryBase.java file. When I run my application I get the following error:
08-28 09:31:02.266: I/dalvikvm(536): threadid=1: stack overflow on call to Landroid/database/sqlite/SQLiteOpenHelper;.<init>:VLLLI
08-28 09:31:02.266: I/dalvikvm(536): method requires 32+20+8=60 bytes, fp is 0x432d1318 (24 left)
08-28 09:31:02.266: I/dalvikvm(536): expanding stack end (0x432d1300 to 0x432d1000)
08-28 09:31:02.266: I/dalvikvm(536): Shrank stack (to 0x432d1300, curFrame is 0x432d3eb8)
08-28 09:31:02.266: D/AndroidRuntime(536): Shutting down VM
08-28 09:31:02.266: W/dalvikvm(536): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
08-28 09:31:02.356: D/dalvikvm(536): GC_FOR_MALLOC freed 4131 objects / 329392 bytes in 47ms
08-28 09:31:02.366: E/AndroidRuntime(536): FATAL EXCEPTION: main
08-28 09:31:02.366: E/AndroidRuntime(536): java.lang.StackOverflowError
08-28 09:31:02.366: E/AndroidRuntime(536): at com.childsoft.icantalk.queries.QueryBase.<init>(QueryBase.java:18)
I’ve never actually run into a stack overflow error before! I’m unsure how to rectify this hrrrm. I have a seperate SchemaHelper which generates my database – working fine. My QueryBase.java looks like this:
public class QueryBase extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "icantalk.db";
private static final int DATABASE_VERSION = 1;
protected SQLiteDatabase sqdb;
protected QueryBase sqh;
public QueryBase(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
this.sqh = new QueryBase(context);
this.sqdb = sqh.getWritableDatabase();
}
@Override
public void onCreate(SQLiteDatabase db) {
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
}
Line 18 on QueryBase is this:
super(context, DATABASE_NAME, null, DATABASE_VERSION);
An example command file that inherits from QueryBase looks like this:
public class ChildCommands extends QueryBase {
public ChildCommands(Context context) {
super(context);
}
public long addChild(String name)
{
ContentValues cv = new ContentValues();
cv.put(ChildrenTable.NAME, name);
SQLiteDatabase sd = super.getWritableDatabase();
long result = sd.insert(ChildrenTable.TABLE_NAME, ChildrenTable.NAME, cv);
return result;
}
}
And an example call on this method would look something like:
private ChildCommands command;
.....
this.command = new ChildCommands(this);
command.addChild(childsNameValue);
This results in creating a new object of QueryBase while creating a new object of QueryBase. This is a never ending call.
Use this:
Edit: btw
sqhis not needed as this variable contains the same instance it is located in (non static!) sosqh == this…