I am implementing SQLite in android to get all the rows data using 2-d strings. But the strings are giving me a null value except for the value of the last index
Code I wrote to get all the data of table
public String[][] getAllData(){
MyDBHelper myDBHelper=new MyDBHelper(context);
SQLiteDatabase db=myDBHelper.getWritableDatabase();
String columns[]={MyDBHelper.UID, MyDBHelper.USERNAME, MyDBHelper.MOBILE,MyDBHelper.EMAIL};
Cursor cursor=db.query(MyDBHelper.TABLE_NAME,columns,null,null,null,null,null);
int index_username=cursor.getColumnIndex(MyDBHelper.USERNAME);
int index_mobile=cursor.getColumnIndex(MyDBHelper.MOBILE);
int index_email=cursor.getColumnIndex(MyDBHelper.EMAIL);
Log.i("tag",Integer.toString(cursor.getCount()));
String strData[][]=new String[cursor.getCount()][3];
while(cursor.moveToNext()){
int index=0;
Log.i("tag",cursor.getString(index_username));
strData[index][0]=cursor.getString(index_username);
strData[index][1]=cursor.getString(index_mobile);
strData[index][2]=cursor.getString(index_email);
Log.i("tag",strData[index][0]+"data");
index++;
}
return strData;
}
the code which called the method
public void getData(){
String data[][]=myDBAdaptor.getAllData();
Log.i("tag", Integer.toString(data.length));
for(int i=0;i<data.length;i++) {
//Log.i("tag",data[i][0]);
String username=data[i][0];
String mobile=data[i][1];
String email=data[i][2];
DataProvider dataProvider= new DataProvider(username,mobile,email);
listDataAdaptor.add(dataProvider);
}
}
the problem Suppose the strData={{"abc","123","xyz"},{"efg","456","pqr"},{"mno","789","fgh"}};
after the execution of this statement data[][]=mydBAdaptor(); the value of data is printing data[][]={{null,null,null},{null,null,null},{"mno","789","fgh"}} why the value are getting null? please help i am trying for hours but could resolve this bug.