Search code examples
classcursorsqliteopenhelper

How to Call a SQLiteOpenHelper Class Having it's name in a String


I have several readable databases in my assets, with the same structure. The user will select the name of a database, and the name of its SQliteOpenHelper class is passed in a String. I successfully initiated the class with Class.forname() but I can't cast Class.getMethod("TableA", null) to Cursor. Can anyone help me get cursors while I only have the SQLiteOpenHelper Class name?


Solution

  • Create a common base class (or interface) for all your classes, then you can directly cast your new object to that type and access its members directly.