Finalizing a Cursor that has not been deactivated or closed
先贴出代码:
public List<UnitInfo> findAllGroup() {
List<UnitInfo> infos=new ArrayList<UnitInfo>();
try {
db = dbManager.openDatabase();
String sql="SELECT * FROM dict_unit_display";
System.out.println("-------db---open------:"+db.isOpen());
cursor=db.query("dict_unit_display", null, null, null, null, null, null);
System.out.println("---------------cursor--close---:"+cursor.isClosed());
while (cursor.moveToNext()) {
UnitInfo unit=new UnitInfo();
unit.setId(cursor.getLong(cursor.getColumnIndex("ID")));
unit.setUnitCode(cursor.getString(cursor.getColumnIndex("UNIT_CODE")));
unit.setUnitName(cursor.getString(cursor.getColumnIndex("UNIT_NAME")));
unit.setUnitSimpleName(cursor.getString(cursor.getColumnIndex("UNIT_SIMPLE_NAME")));
unit.setUnitNode(cursor.getString(cursor.getColumnIndex("UNIT_NODE")));
unit.setUnitFatherNode(cursor.getString(cursor.getColumnIndex("UNIT_NODE_FATHER")));
System.out.println("----------------------------------");
System.out.println("-----ID-----:"+ unit.getId());
System.out.println("-----UNIT_CODE-----:" + unit.getUnitCode());
System.out.println("-----UNIT_NAME-----:" + unit.getUnitName());
System.out.println("-----UNIT_SIMPLE_NAME-----:" + unit.getUnitSimpleName());
System.out.println("-----UNIT_NODE-----:" + unit.getUnitNode());
System.out.println("-----UNIT_NODE_FATHER-----:" + unit.getUnitFatherNode());
System.out.println("----------------------------------");
infos.add(unit);
}
} catch (Exception e) {
System.out.println("------findAllGroup-----数据读取错误");
} finally {
DBManager.closeDatabase(db, cursor);
}
return infos;
}
代码写的看似没有任何问题,但是由于Cursor的独特性,不得不吐糟下,Cursor取值采用的是先取下标再根据下标去取对应的返回值,这里面就有个问题,如果当前字段在数据库中为 空值 那么通过Cursor getString()或者getLong()的时候就会出现问题,进而导致一连串的错误。
解决方法就是直接用下标去取值就行了。
分享到:
相关推荐
A/B分区系统是一种在Android设备上广泛采用的更新机制,旨在提高系统的稳定性和可靠性。它将设备的系统分区划分为两个主要部分:A分区和B分区。通常,A分区是当前正在使用的系统,而B分区则作为备用。当有新的系统...
Java 9 Programming By Example by Peter Verhas English | 26 Apr. 2017 | ASIN: B01KOG6SWI | 504 Pages | AZW3 | 4.1 MB Key Features ...Finalizing Java Knowledge to a Professional Level
Key Features We bridge the gap between “learning” and “doing” by providing real-world examples that will improve your software development ... Finalizing Java Knowledge To A Professional Level
CAD文件版本最终确认是制造业中CAD产品数据管理的重要组成部分,随着市场上竞争的加剧,制造业CAD产品信息日益增多,有效地管理这些CAD产品数据成为了企业迫切的需求。这篇文章提出了一种基于PLM(产品生命周期管理...
Title: Software Application Development: A Visual C++, MFC, and STL Tutorial Author: Bud Fox Ph.D., Tan May Ling M.Sc., Zhang Wenzu Ph.D. Length: 1216 pages Edition: 1 Language: English Publisher: ...
标题“cdiff_finalizing”可能指的是一个特定的项目或者软件工具,它可能是一个用于文本或代码差异比较的程序。在编程领域,特别是Python环境中,差异比较(diff)工具是常用的,它们可以帮助开发者查看两个文件或...
How to design great looking apps that your users will find a pleasure to use The deeper design elements you can apply to your apps What is and how to use Apple’s Human Interface Guidelines (HIG) How ...
that they have the latest information before finalizing their design. The following descriptions of Spansion data sheet designations are presented here to highlight their presence and definitions.
Finalizing a Servlet 195 The mood Example Application 198 Further Information about Java Servlet Technology 200 Part III: Web Services 201 Chapter 11: Introduction to Web Services 203 What Are...
负载生成器在一个终端中: agoric install # takes 20sagoric start local-chain # wait for "finalizing commit..", takes ~4min # leave that running 在第二个终端中: agoric start local-solo 8000 # wait for ...
print("ConcreteClassA is finalizing...") } func preprocess() -> String { return "ConcreteClassA preprocessing..." } } class ConcreteClassB: TemplateProtocol { func prepare() { print(...
Appendix A: Programming Tips and Tricks . . . . . . . . . . . . . . . . . . . . . . . . . 637 Appendix B: Query Performance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 657 ...
NSLog(@"Error finalizing encryption: %d", status); return nil; } encryptedData.length = numBytesEncrypted + kCCBlockSizeAES128; return encryptedData; } ``` 解密过程类似,但使用了`...
1. **AOP概念**:讲解面向切面编程的基本概念,包括切面、通知(Before、After、Around、After-Throwing、After-Finalizing)、连接点、切点、织入等。 2. **Spring AOP**:作为最常用的AOP实现,Spring AOP是Java...
2. **通知(Advice)**:通知是在切面的特定时刻执行的代码片段,如前置通知(Before Advice)、后置通知(After Advice)、异常通知(After-Throwing Advice)、最终通知(After-Finalizing Advice)和环绕通知...
1. 通知:通知是切面在特定时间执行的代码,包括前置通知(Before Advice)、后置通知(After Advice)、异常通知(After-Throwing Advice)、最终通知(After-Finalizing Advice)和环绕通知(Around Advice)。...
切面可以定义自己的通知类型,包括前置通知(Before)、后置通知(After)、环绕通知(Around)、异常通知(After-Throwing)和最终通知(After-Finalizing)。 7. **连接点和切入点**:连接点是程序中可以插入切面...