问题
I added the support library & appcompat to work with lower versions, then the code is working fine in higher versions, but in lower version the app crashes when it tries to fetch data from sqlite.
While running in 2.2 the logcat showing these errors:
07-17 21:46:36.361: I/Database(520): sqlite returned: error code = 1, msg = no such table: Schedules
07-17 21:46:36.371: W/System.err(520): android.database.sqlite.SQLiteException: no such table: Schedules: , while compiling: SELECT DISTINCT * FROM Schedules
07-17 21:46:36.391: W/System.err(520): at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
07-17 21:46:36.391: W/System.err(520): at android.database.sqlite.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:91)
07-17 21:46:36.401: W/System.err(520): at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:64)
07-17 21:46:36.462: W/System.err(520): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:80)
07-17 21:46:36.462: W/System.err(520): at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:46)
07-17 21:46:36.485: W/System.err(520): at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:42)
07-17 21:46:36.492: W/System.err(520): at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1345)
07-17 21:46:36.492: W/System.err(520): at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1315)
07-17 21:46:36.502: W/System.err(520): at com.example.indianconstitution.DBAdapter.getSchedules(DBAdapter.java:148)
07-17 21:46:36.502: W/System.err(520): at com.example.indianconstitution.SchedulesFragment.onCreate(SchedulesFragment.java:37)
07-17 21:46:36.502: W/System.err(520): at android.support.v4.app.Fragment.performCreate(Fragment.java:1477)
07-17 21:46:36.512: W/System.err(520): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:904)
07-17 21:46:36.512: W/System.err(520): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1115)
07-17 21:46:36.512: W/System.err(520): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
07-17 21:46:36.521: W/System.err(520): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1478)
07-17 21:46:36.521: W/System.err(520): at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:446)
07-17 21:46:36.521: W/System.err(520): at android.os.Handler.handleCallback(Handler.java:587)
07-17 21:46:36.521: W/System.err(520): at android.os.Handler.dispatchMessage(Handler.java:92)
07-17 21:46:36.521: W/System.err(520): at android.os.Looper.loop(Looper.java:123)
07-17 21:46:36.521: W/System.err(520): at android.app.ActivityThread.main(ActivityThread.java:4627)
07-17 21:46:36.521: W/System.err(520): at java.lang.reflect.Method.invokeNative(Native Method)
07-17 21:46:36.552: W/System.err(520): at java.lang.reflect.Method.invoke(Method.java:521)
07-17 21:46:36.552: W/System.err(520): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-17 21:46:36.571: W/System.err(520): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-17 21:46:36.571: W/System.err(520): at dalvik.system.NativeStart.main(Native Method)
07-17 21:46:36.661: D/AndroidRuntime(520): Shutting down VM
07-17 21:46:36.661: W/dalvikvm(520): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
07-17 21:46:36.691: E/AndroidRuntime(520): FATAL EXCEPTION: main
07-17 21:46:36.691: E/AndroidRuntime(520): java.lang.NullPointerException
07-17 21:46:36.691: E/AndroidRuntime(520): at com.example.indianconstitution.SchedulesAdapter.<init>(SchedulesAdapter.java:22)
07-17 21:46:36.691: E/AndroidRuntime(520): at com.example.indianconstitution.SchedulesFragment.onCreateView(SchedulesFragment.java:58)
07-17 21:46:36.691: E/AndroidRuntime(520): at android.support.v4.app.Fragment.performCreateView(Fragment.java:1500)
07-17 21:46:36.691: E/AndroidRuntime(520): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:938)
07-17 21:46:36.691: E/AndroidRuntime(520): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1115)
07-17 21:46:36.691: E/AndroidRuntime(520): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
07-17 21:46:36.691: E/AndroidRuntime(520): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1478)
07-17 21:46:36.691: E/AndroidRuntime(520): at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:446)
07-17 21:46:36.691: E/AndroidRuntime(520): at android.os.Handler.handleCallback(Handler.java:587)
07-17 21:46:36.691: E/AndroidRuntime(520): at android.os.Handler.dispatchMessage(Handler.java:92)
07-17 21:46:36.691: E/AndroidRuntime(520): at android.os.Looper.loop(Looper.java:123)
07-17 21:46:36.691: E/AndroidRuntime(520): at android.app.ActivityThread.main(ActivityThread.java:4627)
07-17 21:46:36.691: E/AndroidRuntime(520): at java.lang.reflect.Method.invokeNative(Native Method)
07-17 21:46:36.691: E/AndroidRuntime(520): at java.lang.reflect.Method.invoke(Method.java:521)
07-17 21:46:36.691: E/AndroidRuntime(520): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-17 21:46:36.691: E/AndroidRuntime(520): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-17 21:46:36.691: E/AndroidRuntime(520): at dalvik.system.NativeStart.main(Native Method)
07-17 21:46:36.892: D/dalvikvm(520): GC_FOR_MALLOC freed 3629 objects / 277352 bytes in 181ms
Can anyone tell me why am I facing such type of error in 2.2 ?
I am using rawQuery
to fetch data, from this method
public ArrayList<GS> getSchedules()
{
try{
Cursor c1 = sdb.rawQuery("SELECT DISTINCT * FROM Schedules", null);
gs = new ArrayList<GS>();
while (c1.moveToNext())
{
GS q1 = new GS();
q1.setS_name(c1.getString(1));
q1.setP_name(c1.getString(2));
q1.setDesc(c1.getString(3));
gs.add(q1);
}
}
catch (Exception e) {
e.printStackTrace();
}
return gs;
}
This code works fine in higher versions but not in 2.2 !
Help please
来源:https://stackoverflow.com/questions/24808837/error-no-such-table-in-api-2-2