-1

I have en error, actually code throw an exception. I couldn' read data from sqlite database.

Here is my class whic is the work on database

public class Database extends SQLiteOpenHelper{
public SQLiteDatabase db;

public Database(Context c) 
{
    super(c, c.getDatabasePath("MobileTech.db").toString(), null, 3);

    getWritableDatabase().close();
}

@Override
public void onCreate(SQLiteDatabase db)
{
    Log.e("x", "MobileTech.db oluşturuluyor");

    /**
     * Mobil Kullanıcı Tablosu
     */             
    db.execSQL("CREATE TABLE MOBILEUSERS" + 
    "(ID TEXT PRIMARY KEY, USERNAME TEXT, PASSWORD TEXT)");

}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    // TODO Auto-generated method stub

}

And here is read mobileusers method of this class:

//I try to read mobileusers data here
public ArrayList<MobileUsers> getMobileUsers()
{
    ArrayList<MobileUsers>userList = new ArrayList<MobileUsers>();
    db=getWritableDatabase();
    Cursor cursor = db.rawQuery("SELECT USERNAME,PASSWORD FROM MOBILEUSERS", null);
    while (cursor.moveToNext())
    {
        MobileUsers user = new MobileUsers(cursor.getString(0), cursor.getString(1));
        userList.add(user);
    }
    db.close();
    return userList;
}

And here is the method where is call read database method from database class(I published up)

public ArrayList<MobileUsers> userList()
{
    ArrayList<MobileUsers>userList = new ArrayList<MobileUsers>();
    Database db = new Database(this.c);
    userList = db.getMobileUsers();
    for(MobileUsers mobileUser : userList)
    {
        Log.e("isim", mobileUser.name);
        Log.e("şifre", mobileUser.password);
    }
    return userList;        
}

But I got an exception. This exception is here.

enter image description here

Where is my mistake? I couldn't catch, I couldn't see. Could you help me please?

m.tuğrul
  • 45
  • 1
  • 10

1 Answers1

0

The problem is this line:

super(c, c.getDatabasePath("MobileTech.db").toString(), null, 3);

Either Context c is null, or getDatabasePath("MobileTech.db") is returning null.

JstnPwll
  • 8,585
  • 2
  • 33
  • 56
  • thank you, getDatabasePath("MobileTech.db") mustn't returned null, because if this database doesn't exist it'll create. Maybe Context c is null, I didn't check. I'll check when I'll arrive home. Traffic is so crowded now. Thank you again. – m.tuğrul Oct 09 '15 at 14:30