views:

97

answers:

1

I builded Sqlite database in android application. First i builded main_category table in Sqlite Manager.And then i export that file to my application's raw folder. My Export file is .sql file. That it is here.

 CREATE TABLE "main_category" ("_id" INTEGER PRIMARY KEY  NOT NULL ,"main_image" TEXT,"word_audio_file" TEXT,"char_audio_file" TEXT,"hash_record" BOOL NOT NULL ,"record" TEXT, "menu" TEXT);
    INSERT INTO "main_category" VALUES(1,'g_a.png','g_a.mp3','g_a_01.mp3','false',NULL,NULL);

So I read from my application using FileInputStream. Code is here,

InputStream in= new InputStream() {

                @Override
                public int read() throws IOException {
                    File sqlfile1 = new File("C://CellCity//workspace//GokiriKidApp//res//raw//main_category.sql");
                    return 0;
                }
            };
            try {

                InputStreamReader isr=new InputStreamReader(in);
                BufferedReader br=new BufferedReader(isr);

                SQL_MAIN_CATEGORY= br.readLine();
                in.close();
                br.close();
                isr.close();

            } catch (IOException e) {

                e.printStackTrace();
            }

            Log.i("onCreate", "Database Creation");
            String categoryTString=SQL_MAIN_CATEGORY;
            db.execSQL(categoryTString);

So When i run my code i got error: OutOfMemoryError and lock database in command line(adb shell)

A: 

You are referencing a file on your computer, not on the Android device here:

 File sqlfile1 = new File("C://CellCity//workspace//GokiriKidApp//res//raw//main_category.sql");

If you have placed the file you want to read in the raw folder, then you reference its location on the device using openRawResource(R.raw.fileName)

This will return an inputStream that you can use to read the file, instead of having to create a File object and an inputStream yourself.

Austyn Mahoney