subMap = new HashMap<String, String>();
cursor = sdB.query(DataBase.TB, cols, null, null, null, null, null);
cursor.moveToFirst();
limit = 1;
while(cursor.moveToNext()){
limit +=1;
}
limit *= 2;
cursor.moveToFirst();
do{
for(i=i+1; i<limit; i++){
if(i%2!=0){
subCode = cursor.getString(cursor.getColumnIndex(DataBase.C_CODE));
subMap.put(TAG_SUB_CODE, subCode);
Log.i("Alert", subCode);
subjects.add(subMap);
break;
}
else{
subName = cursor.getString(cursor.getColumnIndex(DataBase.SUB_TITLE));
subMap.put(TAG_SUB_NAME, subName);
if(subMap.containsKey(TAG_SUB_NAME))
Log.i("Alert", "Yes");
if(subMap.containsValue(subName))
Log.i("Alert", "Again Yes");
Log.i("Alert", TAG_SUB_NAME);
Log.i("Alert", subName);
subjects.add(subMap);
}
}
}while(cursor.moveToNext());
cursor.close();
Gives me an NPE on subjects.add(subMap)
in both if and else statement.
First else is executed then if. But program stops at first encounter with it in else block.
Can Anyone please help me.
I checked the existance of value and key in hashmap and it returned me true (yes
and again yes
) in my log cat but still the subjects.add(subMap) returns an NPE.
Thank You