0

The application works on Android 4, 5, and 11 But

I don't know the cause of the problem, but I got Android 9 I hope you can help me
Can you solve this problem please I have received a lot of messages about it I hope you can help me please

problem location in MainActivity.java

public void import_Main_listIndex() {

        listIndex = db_index.get_All_Main_Titles();
        listAdapter adapter1 = new listAdapter(listIndex);
        listView_main.setAdapter(adapter1);
    }
    @SuppressWarnings("unchecked")
    public void import_Sup_listIndex(String main_title) {
        textView_Title.setText(globalVar.getMain_Title());
        listIndex = db_index.get_All_Sub_Titles(main_title);
        listAdapter adapter1 = new listAdapter(listIndex);
        listView_main.setAdapter(adapter1);
    }


    @Override
    protected void onResume() {
        super.onResume();


        String indexType = globalVar.getListType();
        switch (indexType) {
            case "index":
                import_Main_listIndex();
                textView_Title.setText(getString(R.string.index));
                break;
            case "Sup_index":

                import_Sup_listIndex(globalVar.getMain_Title());
                break;
            case "favorite":

                import_from_favorite();
                break;

            case "search":
                search_listIndex();
                break;
        }
    }

databaseHelper.class

public class DatabaseHelper extends SQLiteOpenHelper {
    public static final String DBNAME = "rifai.db";
    public static final String DBLOCATION = Environment.getDataDirectory() + "/data/com.abo3bdo.abcd/databases/";
    private Context mContext;
    private SQLiteDatabase mDatabase;
    private static final int DATABASE_VERSION = 1;


    public DatabaseHelper(Context context) {
        super(context, DBNAME, null, DATABASE_VERSION);
        this.mContext = context;
    }

    @Override
    public void onOpen(SQLiteDatabase db) {
        onCreate(db);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {

    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    }

    public void openDatabase() {
        String dbPath = mContext.getDatabasePath(DBNAME).getPath();
        if (mDatabase != null && mDatabase.isOpen()) {
            return;
        }
        mDatabase = SQLiteDatabase.openDatabase(dbPath, null, SQLiteDatabase.OPEN_READWRITE);
    }

    public void closeDatabase() {
        if (mDatabase != null) {
            mDatabase.close();
        }
    }

    public ArrayList get_All_Main_Titles() {
        ArrayList<com.abo3bdo.abcd.List_itme_Index> arrayList = new ArrayList<>();
        openDatabase();
        Cursor res = mDatabase.rawQuery("select * from Main_Titles", null);
        res.moveToFirst();
        while (!res.isAfterLast()) {
            String id = res.getString(res.getColumnIndex("id"));
            String main_title = res.getString(res.getColumnIndex("M_Titles"));
            arrayList.add(new com.abo3bdo.abcd.List_itme_Index("",id, main_title, ""));
            res.moveToNext();
        }
        res.close();
        closeDatabase();
        return arrayList;
    }

    public ArrayList get_All_Sub_Titles(String main_titles) {
        ArrayList<com.abo3bdo.abcd.List_itme_Index> arrayList = new ArrayList<>();
        openDatabase();
        Cursor res = mDatabase.rawQuery("select * from Titles where Main_title like '" + main_titles + "'", null);
        res.moveToFirst();
        while (!res.isAfterLast()) {
            String id = res.getString(res.getColumnIndex("id"));
            String main_title = res.getString(res.getColumnIndex("Main_title"));
            String sub_title = res.getString(res.getColumnIndex("Sub_title"));
            arrayList.add(new com.abo3bdo.abcd.List_itme_Index("",id, main_title, sub_title));
            res.moveToNext();
        }
        res.close();
        closeDatabase();
        return arrayList;
    }



    public ArrayList get_Search(String sub_titles) {
        ArrayList<com.abo3bdo.abcd.List_itme_Index> arrayList = new ArrayList<>();
        openDatabase();
        Cursor res = mDatabase.rawQuery("select * from Titles where Sub_title like '%" + sub_titles + "%'", null);
        res.moveToFirst();
        while (!res.isAfterLast()) {
            String id = res.getString(res.getColumnIndex("id"));
            String main_title = res.getString(res.getColumnIndex("Main_title"));
            String sub_title = res.getString(res.getColumnIndex("Sub_title"));
            arrayList.add(new com.abo3bdo.abcd.List_itme_Index("",id, main_title, sub_title));
            res.moveToNext();
        }
        res.close();
        closeDatabase();
        return arrayList;
    }


}

logcat

3719-3719/com.abo3bdo.abcd E/AndroidRuntime: FATAL EXCEPTION: main
        Process: com.abo3bdo.abcd, PID: 3719
        java.lang.RuntimeException: Unable to resume activity {com.abo3bdo.abcd/com.abo3bdo.abcd.MainActivity}: android.database.sqlite.SQLiteException: no such table: Main_Titles (code 1 SQLITE_ERROR): , while compiling: select * from Main_Titles
            at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3784)
            at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3816)
            at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:51)
            at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:145)
            at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
            at android.os.Handler.dispatchMessage(Handler.java:106)
            at android.os.Looper.loop(Looper.java:193)
            at android.app.ActivityThread.main(ActivityThread.java:6669)
            at java.lang.reflect.Method.invoke(Native Method)
            at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
         Caused by: android.database.sqlite.SQLiteException: no such table: Main_Titles (code 1 SQLITE_ERROR): , while compiling: select * from Main_Titles
            at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
            at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:903)
            at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:514)
            at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
            at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
            at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
            at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:46)
            at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1408)
            at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1347)
            at com.abo3bdo.abcd.DatabaseHelper.get_All_Main_Titles(DatabaseHelper.java:55)
            at com.abo3bdo.abcd.MainActivity.import_Main_listIndex(MainActivity.java:449)
            at com.abo3bdo.abcd.MainActivity.onResume(MainActivity.java:470)
            at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1412)
            at android.app.Activity.performResume(Activity.java:7292)
            at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3776)
            at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3816) 
            at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:51) 
            at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:145) 
            at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70) 
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808) 
            at android.os.Handler.dispatchMessage(Handler.java:106) 
            at android.os.Looper.loop(Looper.java:193) 
            at android.app.ActivityThread.main(ActivityThread.java:6669) 
            at java.lang.reflect.Method.invoke(Native Method) 
            at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) 
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) 
    2021-07-23 22:11:12.896 3719-3995/com.abo3bdo.abcd I/Ads: Ad failed to load : 2

I hope the lifeguards will be there

Zain
  • 37,492
  • 7
  • 60
  • 84
ghassan
  • 39
  • 4
  • 1
    Does this answer your question? [Caused by: android.database.sqlite.SQLiteException: no such table: (code 1) Android](https://stackoverflow.com/questions/24634116/caused-by-android-database-sqlite-sqliteexception-no-such-table-code-1-andr) – Zain Jul 23 '21 at 19:40
  • It did not help me please I want a solution to the problem – ghassan Jul 23 '21 at 19:50
  • "no such table: Main_Titles" Pretty clear. – javdromero Jul 23 '21 at 19:59
  • Thanks for your interest, but this only happens on Android 9 @javdromero – ghassan Jul 23 '21 at 20:08
  • 1
    https://stackoverflow.com/q/50476782 – Mike M. Jul 23 '21 at 21:59
  • 1
    Does this answer your question? [Android P - 'SQLite: No Such Table Error' after copying database from assets](https://stackoverflow.com/questions/50476782/android-p-sqlite-no-such-table-error-after-copying-database-from-assets) – Jahnavi Paliwal Jul 24 '21 at 04:42

1 Answers1

0

Thanks to everyone who tried to help, the issue has been resolved

public void onOpen(SQLiteDatabase db) {
    super.onOpen(db);
    db.disableWriteAheadLogging();
}

Thank you sir Mike M

ghassan
  • 39
  • 4