• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Deploying a database along with apk file

 
achuthan mukundarajan
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to deploy a database along with my apk , so i modified my sqliteopenhelper as follows:


The problem which people on other forums tell me is to do with the path. I have hard coded the path in my datamanager class as follows:



The application force closes on running on my phone.Please help!
 
ibrahim yener
Ranch Hand
Posts: 202
Android Java PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Probably they are right.
I suggest remove DB path and let android handle it.
 
achuthan mukundarajan
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[quote=ibrahim yener]Probably they are right.
I suggest remove DB path and let android handle it.[/quote]

WHat do you mean?.How do i set the string Db_PATH then?as a null?
 
ibrahim yener
Ranch Hand
Posts: 202
Android Java PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Android will create your DB on default place.
 
achuthan mukundarajan
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ibrahim yener wrote:Android will create your DB on default place.


I tried changing the DB_PATH to just a pair of double quotes. The application still force closes.
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Post the error message and stack trace from the logcat.
 
achuthan mukundarajan
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:Post the error message and stack trace from the logcat.


The problem arises while i use the app on the phone.How do i load the stacktrace for deployment from phone?
 
achuthan mukundarajan
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did a running on the device and got the following logcat

 
achuthan mukundarajan
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I modified the constructor as follows:



I removed a slash at the end of DB_PATH and got the following error in the logcat:

 
ibrahim yener
Ranch Hand
Posts: 202
Android Java PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is what i use as DB helper
As you can see, i am not using path.

[code=java]
public class DatabaseConnection extends SQLiteOpenHelper
{
private final static String DB_NAME = "sample_db.sqlite";
private final static String TABLE = "sample_table";
private final static int DB_VERSION = 1;
private final static String query = "CREATE TABLE IF NOT EXISTS sample_table("
+ "'_id' INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL , 'sample_table_col_1' VARCHAR DEFAULT NULL, "
+ "'sample_table_col_2' VARCHAR, 'date' DATETIME NOT NULL , 'sample_table_col_3' INTEGER NOT NULL , 'sample_table_col_4' INTEGER NOT NULL DEFAULT 1)";

public DatabaseConnection(Context context)
{
super(context, DB_NAME, null, DB_VERSION);
}

@Override
public void onCreate(SQLiteDatabase db)
{
db.execSQL(query);
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
{
db.execSQL("DROP TABLE IF EXIST " + TABLE);
onCreate(db);
}

@Override
public synchronized void close()
{
super.close();
}
}[/code]

Also in your debug code at line 24 says "05-02 16:25:32.835: E/AndroidRuntime(10275): java.lang.Error: database does't exist yet. "
seems you are trying to reach DB which is not created yet.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic