All of sudden problems working with sqlite database

Put your problem here if it does not fit any of the other categories.

All of sudden problems working with sqlite database

Postby Katharnavas » Thu Jan 10, 2008 1:36 pm

Hi,
I was trying application with sqlite database from

http://www.anddev.org/working_with_the_ ... -t319.html

which worked like a pro. But also of sudden today when i launched i could see only a empty list and a error message indicating
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. E/Database(550): Failed to open database file "databases/SampleDB" - unable to open database file
Parsed in 0.029 seconds, using GeSHi 1.0.8.4


when i checked with commandline the database contains tables and it has data.

What happened to the database? Why all of a sudden its throwing the exception?

I tried some other example using database and all i got was the same result ?

Any suggestions to overcome this issue ?
Katharnavas
Senior Developer
Senior Developer
 
Posts: 100
Joined: Tue Dec 04, 2007 5:57 am
Location: India

Top

Postby plusminus » Fri Jan 11, 2008 9:36 pm

Hello Katharnavas,

I haven't received this yet, but perhaps the emulator was closed at a state at which it should not have been (ok the dbms should have managed to restore, but we cannot know that exactly...)
But in that case the access from "outside" should also not work.

Could you "fix" it with a "-wipe-data" :?:

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby Katharnavas » Sat Jan 12, 2008 5:00 am

Hi,
Thats the best thing i had done.. Used -wipe -data and resolved that problem. But this is not the best way of doing for all the unknown problems.
Katharnavas
Senior Developer
Senior Developer
 
Posts: 100
Joined: Tue Dec 04, 2007 5:57 am
Location: India

Postby plusminus » Sat Jan 12, 2008 11:03 am

you are so right :lol:
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Null Pointer Exception while creating table

Postby Niketa » Mon Sep 29, 2008 11:37 am

hi,
I have implement this example. but i got an error.

I have write the code just for create database, create table, insert values in it.

When I run application it displays nothing.

But when i tried to open my database from command prompt Like:

ls data/data/MyPackageNm

Then it gives only a Lib folder rather than database and Lib both.

So, i tried to found error via Log cat and put my code in try and catch.

I got an error while creating table.

its gave Null Pointer exception.

Please any one help me.

My Log cat is like that and i have use this sample example as my code.

Thanks.

Code: Select all
uid=10032 gids={}
09-29 15:36:09.727: DEBUG/dalvikvm(813): LinearAlloc 0x0 used 538516 of 4194304 (12%)
09-29 15:36:09.837: INFO/jdwp(822): received file descriptor 10 from ADB
09-29 15:36:10.128: INFO/Niketa(822): database created
09-29 15:36:10.137: INFO/Niketa(822): database opened
09-29 15:36:10.137: INFO/Niketa(822): ------null
09-29 15:36:10.147: INFO/Niketa(822): ++++++java.lang.NullPointerException
09-29 15:36:10.337: INFO/ActivityManager(52): Displayed activity com.db/.DataBaseWork: 754 ms
09-29 15:36:15.507: DEBUG/dalvikvm(675): GC freed 44 objects / 1800 bytes in 151ms
09-29 15:36:15.507: DEBUG/dalvikvm(118): GC freed 3 objects / 72 bytes in 143ms
09-29 15:36:15.527: DEBUG/dalvikvm(92): GC freed 1539 objects / 70560 bytes in


My java code is:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package com.db;
  2.  
  3. //import java.io.FileNotFoundException;
  4. import java.util.ArrayList;
  5.  
  6. import android.app.Activity;
  7. import android.database.Cursor;
  8. import android.database.SQLException;
  9. import android.database.sqlite.SQLiteDatabase;
  10. import android.database.sqlite.SQLiteException;
  11. import android.os.Bundle;
  12. import android.util.Log;
  13. import android.widget.ArrayAdapter;
  14.  
  15. public class DataBaseWork extends Activity {
  16.         private final String MY_DATABASE_NAME = "LoginDB";
  17.     private final String MY_DATABASE_TABLE = "Login1";
  18.     private final String tag="Niketa";
  19.  
  20.  
  21.     @Override
  22.     public void onCreate(Bundle icicle) {
  23.          super.onCreate(icicle);
  24.  
  25.          ArrayList<String> results = new ArrayList<String>();
  26.          SQLiteDatabase myDB = null;
  27.          try {
  28.                
  29.               /* Create the Database (no Errors if it already exists) */
  30.               this.createDatabase(MY_DATABASE_NAME, 1, MODE_PRIVATE, null);
  31.               Log.i(tag,"database created");
  32.  
  33.               /* Open the DB and remember it */
  34.                
  35.               myDB = this.openDatabase(MY_DATABASE_NAME, null);
  36.               Log.i(tag,"database opened ");
  37.                
  38.               /* Create a Table in the Database. */
  39.               try
  40.               {
  41.               myDB.execSQL("CREATE TABLE IF NOT EXISTS "
  42.                                   + "LoginDB.Login1"
  43.                                   + " (UserNm TEXT, PassWd TEXT)"
  44.                                   +";");
  45.               Log.i(tag,"table created ");
  46.               }
  47.           /*    catch(SQLException e1)
  48.               {
  49.                   Log.i(tag,"SQL EXception"+e1);
  50.               }*/
  51.              
  52.              
  53.               catch(Exception e)
  54.               {
  55.                   Log.i(tag,"------"+e.getMessage());
  56.                   Log.i(tag,"++++++"+e);
  57.               }
  58.              
  59.             /*  catch(SQLiteException se)
  60.               {
  61.                   Log.i(tag,"SQLite Error--------"+se);
  62.               }*/
  63.               /* Add two DataSets to the Table. */
  64.               myDB.execSQL("INSERT INTO "
  65.                                   + MY_DATABASE_TABLE
  66.                                   + " (UserNm, PassWd)"
  67.                                   + " VALUES ('abc', 'def');");
  68.               Log.i(tag,"value inserted ");
  69.              
  70.              
  71.               /* Query for some results with Selection and Projection. */
  72.               Cursor c = myDB.rawQuery("SELECT UserNm,PassWd" +
  73.                                        " FROM " + MY_DATABASE_TABLE
  74.                                        + ";",
  75.                                        null);
  76.               Log.i(tag,"value seleted ");
  77.              
  78.               /* Get the indices of the Columns we will need */
  79.               int firstNameColumn = c.getColumnIndex("UserNm");
  80.               int ageColumn = c.getColumnIndex("PassWd");
  81.              
  82.               /* Check if our result was valid. */
  83.               if (c != null) {
  84.                    /* Check if at least one Result was returned. */
  85.                   if (c.isFirst()) {
  86.                         int i = 0;
  87.                      
  88.                         do {
  89.                              i++;
  90.                      
  91.                              String firstName = c.getString(firstNameColumn);
  92.                              int age = c.getInt(ageColumn);
  93.                              String ageColumName = c.getColumnName(ageColumn);
  94.                              
  95.                              results.add("" + i + ": " + firstName
  96.                                             + " (" + ageColumName + ": " + age + ")");
  97.                         } while (c!=null);
  98.                    }
  99.               }
  100.          }
  101.          catch (Exception e)
  102.          {
  103.                  Log.i(tag,"Error----->"+e);
  104.          }
  105.          finally
  106.          {
  107.               if (myDB != null)
  108.                    myDB.close();
  109.          }
  110.          this.setListAdapter(new ArrayAdapter<String>(this,
  111.                  android.R.layout.simple_list_item_1, results));
  112.   }
  113.  
  114.  
  115.         private void setListAdapter(ArrayAdapter<String> arrayAdapter)
  116.         {
  117.         }
  118.  
  119.         private SQLiteDatabase openDatabase(String my_database_name2, Object object)
  120.         {
  121.                 return null;
  122.         }
  123.  
  124.         private void createDatabase(String my_database_name2, int i,
  125.                         int modePrivate, Object object)
  126.         {
  127.        
  128.                
  129.         }
  130. }
  131.  
Parsed in 0.049 seconds, using GeSHi 1.0.8.4
Niketa
Developer
Developer
 
Posts: 36
Joined: Wed Sep 17, 2008 12:37 pm

Postby cgreen » Mon Sep 29, 2008 1:27 pm

maybe:

/* Create a Table in the Database. */
try
{
myDB.execSQL("CREATE TABLE IF NOT EXISTS "
+ MY_DATABASE_TABLE
+ " (UserNm TEXT, PassWd TEXT)"
+";");
Log.i(tag,"table created ");
}
localhost is the android emulator
User avatar
cgreen
Experienced Developer
Experienced Developer
 
Posts: 56
Joined: Wed Jul 16, 2008 10:16 am

Top

its not working

Postby Niketa » Mon Sep 29, 2008 1:44 pm

hi,
Thanks for the Help.

But its still not working.
Niketa
Developer
Developer
 
Posts: 36
Joined: Wed Sep 17, 2008 12:37 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 16 guests