歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Android程序查詢包含“*" "#”的號碼時出錯的解決辦法

Android程序查詢包含“*" "#”的號碼時出錯的解決辦法

日期:2017/3/1 10:17:58   编辑:Linux編程

代碼錯誤提示:
E/AndroidRuntime(1145): Caused by: android.database.sqlite.SQLiteException: near "*": syntax error: , while compiling: SELECT numbertype, new, duration, _id, numberlabel, name, number, type, date FROM calls WHERE (number = **9) ORDER BY date desc

解決:

  1. strQuery = "number = " + strQueryNumber;
  2. callLogCursor = TApplication.nowTApplication.getContentResolver()
  3. .query(CallLog.Calls.CONTENT_URI, null, strQuery, null,
  4. "date desc");

查詢代碼改成:

  1. strQuery = "number = " + "'strQueryNumber'";
  2. callLogCursor = TApplication.nowTApplication.getContentResolver()
  3. .query(CallLog.Calls.CONTENT_URI, null, strQuery, null,
  4. "date desc");

總結:因為"*"為數據庫裡的關鍵字(未經證實),所有查找是會報語法錯誤,只需要拼接字符串,把"*"改成非關鍵字即可

ps:模擬器不知道為何直接拔打數字+"#"會清空屏幕,而只能撥打"#"開頭的號碼

Copyright © Linux教程網 All Rights Reserved