Exception: Type mismatch
05-06 08:12:38.151:e/androidruntime (14904): Java.lang. numberformatexception:invalid int: "18600000099"
05-06 08:12:38.151:e/androidruntime (14904): at com.itheima.mobilesafe74.activity.blacknumberactivity$ Myadapter.getview (blacknumberactivity.java:122)
1 PublicList<blacknumberinfo> Find (intindex)2 {3 //to get the database object first4Sqlitedatabase db =blacknumberopenhelper.getwritabledatabase ();5 //The first parameter in Db.rawquery () is the SQL statement, and the second parameter is? The corresponding value6 cursor cursor = db.rawquery ("SELECT * from Blacknumber ORDER by _id desc limit?", " new string[]{index+" " });7 //in order to get all the fields found, create a collection package8List<blacknumberinfo> blacknumberlist =NewArraylist<blacknumberinfo>();9 while(Cursor.movetonext ())Ten { One //encapsulates two fields of a query into a Java bean ABlacknumberinfo Blacknumberinfo =Newblacknumberinfo (); - blacknumberinfo.phone = cursor.getstring (0); Blacknumberinfo.mode = cursor.getstring (1); the //Each loop encapsulates the JavaBean into the collection. - Blacknumberlist.add (blacknumberinfo); - } - cursor.close (); + db.close (); - returnblacknumberlist; +}
Code line Sixth
SELECT * FROM Blacknumber
Represents all fields of the query
and
There are _id,phone,mode three fields in the database
So when calling code 13, 14 lines
Blacknumberinfo.phone = cursor.getstring (0); blacknumberinfo.mode = cursor.getstring (1);
0 corresponds to the _id, not the phone.
1 corresponds to the phone, not the mode.
So there's a problem.
Modify the SQL query statement to solve this problem:
For the six lines, replace
cursor cursor = db.rawquery ("Select Phone,mode from Blacknumber ORDER by _id desc limit?", New string[]{index+ ""} );
Can
Numberformatexception:invalid int Type mismatch exception--Use SQL database query statement SELECT * FROM Blacknumber ORDER by _id desc limit?, 20; appears