public Person find(Integer id) {
SQLiteDatabase db = dbOpenHelper.getReadableDatabase();
Cursor cursor = db.rawQuery("select * from person where personId=?",
new String[] { id.toString()});
if (cursor.moveToFirst()) {
int personid = cursor.getInt(cursor.getColumnIndex("personId"));
String name = cursor.getString(cursor.getColumnIndex("name"));
int age = cursor.getInt(cursor.getColumnIndex("age"));
String phone = cursor.getString(cursor.getColumnIndex("phone"));
return new Person(personid, name, age, phone);
}
cursor.close();
return null;
}

原来SQLite 数据库是有区分字母大小写的,修改前,运行提示出错:
java.lang.IllegalStateException: get field slot from row 0 col -1 failed
at android.database.CursorWindow.getLong_native(Native Method)
at android.database.CursorWindow.getInt(CursorWindow.java:434)
at android.database.AbstractWindowedCursor.getInt(AbstractWindowedCursor.java:93)
at cn.lyun.service.PersonService.find(PersonService.java:60)
at cn.lyun.test.PersonServiceTest.testFind(PersonServiceTest.java:32)
at java.lang.reflect.Method.invokeNative(Native Method)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:529)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1448)

更多相关文章

  1. Android统计EditText的字母数字以及汉字的统计方法
  2. Android 之 Fast Scroll 、字母索引栏
  3. Android ListView城市列表,按a-z分组字母索引排序
  4. Android 怎么防止AlertDialog Button按钮字母变大写
  5. Android中使用indexablerecyclerview以及右侧字母索引基本使用
  6. android ListView根据字母排序和定位
  7. Android 通讯录中用到的关于按名字首字母排序方法

随机推荐

  1. Android实现自定义View的自定义属性的一
  2. Android媒体播放---Media playback(二)
  3. mars老师推荐的学习android路线
  4. 电池寿命:Android“电池”工具是如何工作
  5. [Android]单机斗地主,破解版,无广告
  6. 关于从Eclipse导入项目到android studio
  7. 基于华视身份证读卡器读取身份证信息的An
  8. 想写出更好的应用?Google“Android Traini
  9. Android中打包含有Activity以及资源文件
  10. android RecyclerView一步步打造分组效果