In my database there are 2 tables. One for login info and another for store some report data. When i try to insert data in login table, it is successful. But when i try to insert report data, i get "NullPointerException" error. In different ways i checked and confirm that i am not sending any null value.
Please check the code below.
public class StoreReport {
public static final String KEY_ROWID = "_uid";
public static final String KEY_NAME = "username";
public static final String KEY_password = "userpassword";
private static final String DATABASE_NAME = "personal.db";
private static final String DATABASE_TABLE1 = "user";
private static final String DATABASE_TABLE2 = "dailyreport";
private static final int DATABASE_VERSION = 1;
private DbHelper ourHelper;
private final Context ourContext;
private SQLiteDatabase ourDatabase;
private static class DbHelper extends SQLiteOpenHelper {
public DbHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE " + DATABASE_TABLE1 + "(" +
KEY_ROWID + " INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, " +
KEY_NAME + " TEXT NOT NULL, " +
KEY_password + " INTEGER NOT NULL " +
");"
);
db.execSQL("CREATE TABLE " + DATABASE_TABLE2 + "(" +
" _rid INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, " +
" reportdate TEXT, " +
" qutelawat INTEGER, " +
" qustudy INTEGER, " +
" hadstudy INTEGER, " +
" bookstudy INTEGER, " +
" namaj_jamat INTEGER, " +
" namaj_kaja INTEGER, " +
" dawahcont INTEGER, " +
" manpcont INTEGER, " +
" progjoin INTEGER, " +
" orgtime INTEGER, " +
" digitaltime INTEGER, " +
" pstudy INTEGER, " +
" family INTEGER, " +
" society INTEGER, " +
" selfrel INTEGER " +
");"
);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE1);
db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE2);
onCreate(db);
}
}
public StoreReport(Context c) {
ourContext = c;
}
public StoreReport open() {
ourHelper = new DbHelper(ourContext);
ourDatabase = ourHelper.getWritableDatabase();
return this;
}
public void close() {
ourDatabase.close();
}
public long createEntryUser(String uname, String upass) {
ContentValues cv = new ContentValues();
cv.put(KEY_NAME, uname);
cv.put(KEY_password, upass);
long i = ourDatabase.insert(DATABASE_TABLE1, null, cv);
return i;
}
public long createEntryReport(String data1, int data2, int data3, int data4,
int data5, int data6, int data7, int data8,
int data9, int data10, int data11, int data12,
int data13, int data14, int data15, int data16) {
ContentValues cv1 = new ContentValues();
cv1.put("reportdate", data1);
cv1.put("qutelawat", data2);
cv1.put("qustudy", data3);
cv1.put("hadstudy", data4);
cv1.put("bookstudy", data5);
cv1.put("namaj_jamat", data6);
cv1.put("namaj_kaja", data7);
cv1.put("dawahcont", data8);
cv1.put("manpcont", data9);
cv1.put("progjoin", data10);
cv1.put("orgtime", data11);
cv1.put("digitaltime", data12);
cv1.put("pstudy", data13);
cv1.put("family", data14);
cv1.put("society", data15);
cv1.put("selfrel", data16);
try {
long i = ourDatabase.insert(DATABASE_TABLE2, null, cv1);
return i;
} catch (Exception e) {
e.printStackTrace();
return -1;
}
}
public boolean verify_user(String pass) {
String p;
String[] data = new String[]{KEY_ROWID, KEY_NAME, KEY_password};
Cursor cr = ourDatabase.query(DATABASE_TABLE1, data,
KEY_password + " = '" + pass + "'", null, null, null, null);
if (cr.getCount() == 1) {
cr.moveToFirst();
p = cr.getString(2);
return p.equals(pass) ? true : false;
} else {
return false;
}
}
}
Aucun commentaire:
Enregistrer un commentaire