版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/ReturningProdigal/article/details/82251866
问题代码:
String sortOrder = "_id DESC";
Cursor cursor = getContentResolver().query(Telephony.Carriers.CONTENT_URI, null, null, null, sortOrder);
if(null == cursor){
return;
}
int count = cursor.getCount();
int tmp = 0;
while (cursor.moveToNext()) {
int id = cursor.getInt(cursor.getColumnIndex("_id"));
String name = cursor.getString(cursor.getColumnIndex("name"));
if(name.equals("parkin")){
String a = name;//此处断点,我想看下当name为"parkin"时,其他的值
}
String apn = cursor.getString(cursor.getColumnIndex("apn")).toLowerCase();
String type = cursor.getString(cursor.getColumnIndex("type")).toLowerCase();
}
cursor.close();
然而我将 “content://telephony/carriers” 所指向的数据库 “/data/data/com.android.providers.telephony/databases/telephony.db” adb pull 出来,然后用 Navicat 查看,数据库中存在 name为”parkin” 的记录。尴尬了。怎么代码里面调试没有呢?
突然灵光一现,恍然大悟!!!
String a = name;
这一句代码是对 name 作引用,并没有指令,再编译链接后,不产生二进制指令,只是在编译是起到变量引用作用。
解决方案:
String sortOrder = "_id DESC";
Cursor cursor = getContentResolver().query(Telephony.Carriers.CONTENT_URI, null, null, null, sortOrder);
if(null == cursor){
return;
}
int count = cursor.getCount();
String a = null;
while (cursor.moveToNext()) {
int id = cursor.getInt(cursor.getColumnIndex("_id"));
String name = cursor.getString(cursor.getColumnIndex("name"));
if(name.equals("parkin")){
a = name;
}
String apn = cursor.getString(cursor.getColumnIndex("apn")).toLowerCase();
String type = cursor.getString(cursor.getColumnIndex("type")).toLowerCase();
}
cursor.close();
将 a 的申明初始化放置在外边,然后在 if 中 使用给变量赋值。然后就可以了。
虽然只是一行代码,但其中的含义值得深思啊!!!