/**
* * title:selectallphone *description: Query All Phone objects * @return * @see
* Com.sms.ntlm.dao.phonedao#selectallphone ()
*/
@SuppressLint ("SimpleDateFormat")
@SuppressWarnings ("deprecation")
@Override
Public list<phone> Selectallphone () {
Cursor cursor=null;
list<phone> list=new arraylist<phone> ();
String sql= "select * from" +phonesqlconstant.table_name+ ";";
db=mopenhelper.getwritabledatabase ();
if (mopenhelper!=null && db.isopen ()) {
//Cursor=db.query (phonesqlconstant.table_name, NULL, NULL, NULL , NULL, NULL, NULL);
cursor=db.rawquery (SQL, NULL);
}
if (cursor! = NULL) {//cause this is where the error occurred: I added an if (cursor! = NULL && Cursor.movetofirst ()) to this place {
While (Cursor.movetonext ()) {
phone phone=new phone ();
Phone.setphoneid (Cursor.getint (Cursor.getcolumnindex (phonesqlconstant.phone_id)));
Phone.setphonenum (cursor.getstring (Cursor.getcolumnindex (Phonesqlconstant.phone_num)));
phone.setphonedate (cursor.getstring (Cursor.getcolumnindex (phonesqlconstant.phone_date)));
List.add (phone);
}
}
This.closecursordb (cursor);
return list;
}
The result of the console output is : 05-15 03:12:44.017:i/system.out (12634): Testselectallphone.size (...) ..... 0
The result of my query in the database is:
D:\zzz>sqlite3 phonemassage.db
SQLite version 3.7.11 2012-03-20 11:35:50
Enter '. Help ' for instructions
Enter SQL statements terminated with a ";"
Sqlite>. Table
Myphone Phone Android_metadata
Sqlite> SELECT * from Myphone
...>;
1|1234|2015-05-15
Sqlite> ^c
The first data in the
SQLite database cannot be found!