Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6901695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:42:20+00:00 2026-05-27T07:42:20+00:00

I am now writing an app which needs some prepared data in the database,

  • 0

I am now writing an app which needs some prepared data in the database, I tried the method from this question

Ship an application with a database

and it turn out you can’t copy database in android 2.3.

So I set up a splash screen and want to run some data initialisation there.

I tried Thread and Asyctask but still getting this curious problem that my insert_data method keep getting exception

It’s getting me mad,plz help

Splash.java

public class Splash extends Activity {

     private ChannelDB mDB;
     private TextView loading;
     private String channelS_TABLE;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash);  
        new SetDB().execute();

    }

    private class SetDB extends AsyncTask<String, String, String> {

        @Override
        protected String doInBackground(String... arg0) {
            // TODO Auto-generated method stub
            try {
                Log.d("Splash","table check not running yet");
                if (tabIsExist(channelS_TABLE) != true ){
                    Log.d("Splash","table check complete and not exist");
                    mDB.Reset();
                    Log.d("Splash","database reset");
                      some data insert
                     ));
                }else{
                    synchronized(this){
                        Log.i("Splash", "the table is there");
                        wait(3000);}
                    Intent i = new Intent();
                    i.setClassName("com.appkon.hdtvs",
                                   "com.appkon.hdtvs.HDtvs");
                    finish();
                    startActivity(i);
                }   
               }catch (Exception e) {

                    Log.i("Splash", "setDB exception");
                        Intent i = new Intent();
                        i.setClassName("com.appkon.hdtvs",
                                       "com.appkon.hdtvs.HDtvs");
                        finish();
                        startActivity(i);
                    }
            return null;
        }


        protected void onPreExecute(String load) {

        }

        protected void onPostExecute(String finish) {
             Intent i = new Intent();
             i.setClassName("com.appkon.hdtvs",
                            "com.appkon.hdtvs.HDtvs");
             finish();
             startActivity(i);
        }
    }


        public boolean tabIsExist(String tableName){
            boolean result = false;
            if(tableName == null){
                    return false;
            }
            Cursor cursor= ChannelDB.check();
            startManagingCursor(cursor);
            try {
                    if(cursor.moveToNext()){
                            int count = cursor.getInt(0);
                            if(count>0){
                                    result = true;
                            }
                    }

            } catch (Exception e) {
                Log.e(this.toString(),"error:"+e.toString());
                Intent intent = new Intent(this,HDtvs.class);  
                startActivity(intent);  
                this.finish(); 
                Log.d("Splash","tabIsExist Exception");
            }                
            return result;
        }


    }

Error track

12-05 07:52:20.542: INFO/System.out(575): debugger has settled (1460)
12-05 07:52:21.442: DEBUG/dalvikvm(575): GC freed 679 objects / 53552 bytes in 135ms
12-05 07:52:21.932: DEBUG/Splash(575): table check not running yet
12-05 07:52:21.932: DEBUG/Splash(575): table check complete and not exist
12-05 07:52:21.932: INFO/Splash(575): setDB exception
12-05 07:52:21.982: INFO/ActivityManager(51): Starting activity: Intent { cmp=com.appkon.hdtvs/.HDtvs }
12-05 07:52:22.482: WARN/ActivityManager(51): Duplicate finish request for HistoryRecord{44d4aa10 com.appkon.hdtvs/.Splash}
12-05 07:52:22.502: INFO/ActivityManager(51): Starting activity: Intent { cmp=com.appkon.hdtvs/.HDtvs }

Thx for Bindal’s great solution, but I still have a problem, I defined a method to add entry in my database helper class and insert data into database using it, but it seems not working

this is my method defined in databasehelper class

 public void createchannelEntry(ChannelPoster channel) {
        openDB();
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        channel.getPoster().compress(Bitmap.CompressFormat.PNG, 100, out);
        ContentValues cv = new ContentValues();
        cv.put(KEY_POSTER, out.toByteArray());            
        cv.put(KEY_CHANNEL, channel.getChannel());
        cv.put(KEY_PATH, channel.getPath());
        cv.put(KEY_DBLINK, channel.getDBlink());

        mDb.insert(channelS_TABLE, null, cv);
        closeDB();
    }

this is how I insert data

Bitmap sherlock = BitmapFactory.decodeResource(getResources(), R.drawable.sherlock);

mDB.createchannelEntry(new ChannelPoster(aa, "aa" ,"ll"  ,"ha" ));

and I have a JavaBean for holding an entry

public class ChannelPoster {
    private Bitmap poster;
    private String channel;
    private String path;
    private String dblink;

    public ChannelPoster(Bitmap pi, String c, String p, String d) {
        poster = pi;
        channel = c;
        path = p;
        dblink = d;
    }

    public Bitmap getPoster() { return poster; }
    public String getChannel() { return channel; }
    public String getPath() { return path; }
    public String getDBlink() { return dblink; }
}

Now I am adding Logcat record here

this is my codes here

 public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash);  
        try {
            createDataBase();
        } catch (Exception e) {
               Intent intent = new Intent(this,HDtvs.class);  
               startActivity(intent);  
               this.finish(); 
               Log.d("Splash","createDataBaseException");
        }
    }

    public void createDataBase() throws Exception 
    {
       boolean dbExist = checkDataBase();
       if (dbExist){
           Intent intent = new Intent(this,HDtvs.class);  
           startActivity(intent);  
           this.finish(); 
           Log.d("Splash","table exist");
       }
       else
       {
           try{
                mDB.Reset();
                Log.d("Splash","database reset");
                Bitmap bigbang1 = BitmapFactory.decodeResource(getResources(), R.drawable.bigbang1);


                mDB.createchannelEntry(new ChannelPoster(bigbang1, "生活大爆炸(第一季)" ,"http://appkon.com/hdtvs/channel/bigbang1.xml"  ,"http://movie.douban.com/subject/5372374/" ));

           }catch (Exception e){
               Log.d("splash","data insert exception");
               Intent intent = new Intent(this,HDtvs.class);  
               startActivity(intent);  
               this.finish(); 
           }
       }
    }

   /**
    * Check if the database already exist to avoid re-copying the file each
    * time you open the application.
    * 
    * @return true if it exists, false if it doesn't
    */
   private boolean checkDataBase() 
    {
       SQLiteDatabase checkDB = null;
       try 
       {
           String myPath = "data/data/com.appkon.hdtvs/databases/" + "channelDB";
           checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READWRITE);
       }catch (Exception e){
           Log.d("Splash","database does't exist yet.");
       }

       if (checkDB != null){
           checkDB.close();

           return true;
       }
       else 
           return false;
    }
}

And this is my logcat record

> 12-05 08:35:14.222: INFO/System.out(824): debugger has settled (1435)
> 12-05 08:35:15.032: DEBUG/dalvikvm(824): GC freed 621 objects / 51304
> bytes in 98ms 12-05 08:35:15.373: ERROR/Database(824):
> sqlite3_open_v2("data/data/com.appkon.hdtvs/databases/channelDB",
> &handle, 2, NULL) failed 12-05 08:35:15.382: DEBUG/Splash(824):
> database does't exist yet. 12-05 08:35:15.382: DEBUG/splash(824): data
> insert exception 12-05 08:35:15.402: INFO/ActivityManager(51):
> Starting activity: Intent { cmp=com.appkon.hdtvs/.HDtvs } 12-05
> 08:35:16.753: INFO/ActivityManager(51): Displayed activity
> com.appkon.hdtvs/.HDtvs: 1298 ms (total 6152 ms)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T07:42:20+00:00Added an answer on May 27, 2026 at 7:42 am
    public void createDataBase() throws Exception 
         {
            boolean dbExist = checkDataBase();
            if (dbExist){
                System.out.println("Database Exist");
            }
            else
            {
                this.getReadableDatabase();
                try{
    
                }catch (Exception e){
                    throw new Error(e.getMessage());
                }
            }
         }
    
        /**
         * Check if the database already exist to avoid re-copying the file each
         * time you open the application.
         * 
         * @return true if it exists, false if it doesn't
         */
        private boolean checkDataBase() 
         {
            SQLiteDatabase checkDB = null;
            try 
            {
                String myPath = DB_PATH + DB_NAME;
                checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READWRITE);
            }catch (Exception e){
                System.out.println("database does't exist yet.");
            }
    
            if (checkDB != null){
                checkDB.close();
                System.out.println("My db is:- " + checkDB.isOpen());
                return true;
            }
            else 
                return false;
         }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My app needs to pull data from MULTIPLE sources. The following needs to be
I'm writing an app which needs to process a large text file (comma-separated with
I began writing an app using declarative_authorization ( http://github.com/stffn/declarative_authorization ) but I'm now wondering
I am writing an iframe based facebook app. Now I want to use the
I've been writing a few web services for a .net app, now I'm ready
Right now I am writing a simulation program which output is formatted according to
In the app I'm writing I have a bunch of stats which I want
im writing an application that downloads and installs addons for programs which needs to
I am writing a Tomcat app. As part of its functionality, it needs to
I'm writing a Windows Phone 7 app that needs to be location aware. Specifically

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.