我有一个应用程序,它记录了前台活动的几个属性。我使用本地数据库来存储数据,当用户请求显示时,我从该数据库中获取数据并将其显示在列表视图中。它在 GB、ICS 上运行良好。但是 JellyBean 中的数据库事务非常不规则。空的被退回。我无法知道这其中的原因。我已经在 Samsung young、HTC、索尼爱立信 Xperia 和三星 S3 上对此进行了测试。问题在于已更新为 JB 的 S3。以下是 logCat 跟踪。请帮忙。
try {
db.open();
Cursor cursor = db.getStartTime(lastAppName); ;
if(cursor.moveToFirst()) {
do {
DiffStart = cursor.getString(0);
DiffBright = cursor.getString(1);
Log.d("wifiRun","brightness: " +DiffBright);
}while(cursor.moveToNext());
}
SimpleDateFormat dateFormat = new SimpleDateFormat(
"HH:mm:ss");
try {
Date startTime = dateFormat.parse(DiffStart);
Date endTime = dateFormat.parse(EndingTime);
diff = (endTime.getTime() - startTime.getTime()) / 1000;
Difference = String.valueOf(diff);
try {
double brightnessDouble = Double.parseDouble(DiffBright);
Log.d("wifiRun","brightnessDouble: " +brightnessDouble);
//Do my energy calculation.
} catch (NullPointerException npe) {
npe.printStackTrace();
}
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NullPointerException npe) {
npe.printStackTrace();
}
db.update(lastAppName, EndingTime, Difference, AppEnergy);
Cursor cur = db.Select(lastAppName);
if(cursor.moveToFirst()) {
do {
testBright = cursor.getString(0);
Log.d("wifiRun","testBright: " +testBright);
testEnergy = cursor.getString(1);
Log.d("wifiRun","testEnergy: " +testEnergy);
}while(cursor.moveToNext());
}
db.close();
} catch (SQLException sql) {
sql.printStackTrace();
}
LogCat如下:
06-11 12:57:31.258: D/wifiRun(32469): brightness: 171
06-11 12:57:31.258: D/wifiRun(32469): brightness: null
06-11 12:57:31.258: D/wifiRun(32469): brightness: null
06-11 12:57:31.258: D/wifiRun(32469): brightness: 171
06-11 12:57:31.258: D/wifiRun(32469): brightness: 171
06-11 12:57:31.258: D/wifiRun(32469): brightness: 171
06-11 12:57:31.258: D/wifiRun(32469): brightness: 171
06-11 12:57:31.258: D/wifiRun(32469): brightness: 171
06-11 12:57:31.258: D/wifiRun(32469): brightness: 171
06-11 12:57:31.258: D/wifiRun(32469): brightness: 171
06-11 12:57:31.263: D/wifiRun(32469): brightnessDouble: 171.0
06-11 12:57:31.263: D/wifiRun(32469): AppEnergy: 13.977
06-11 12:57:31.268: D/wifiRun(32469): testEnergy: null
06-11 12:57:31.268: D/wifiRun(32469): testBright: 171
06-11 12:57:31.268: D/wifiRun(32469): testEnergy: null
06-11 12:57:31.268: D/wifiRun(32469): testBright: null
06-11 12:57:31.268: D/wifiRun(32469): testEnergy: null
06-11 12:57:31.268: D/wifiRun(32469): testBright: null
06-11 12:57:31.268: D/wifiRun(32469): testEnergy: 313.776
06-11 12:57:31.268: D/wifiRun(32469): testBright: 171
06-11 12:57:31.268: D/wifiRun(32469): testEnergy: 313.776
06-11 12:57:31.268: D/wifiRun(32469): testBright: 171
06-11 12:57:31.268: D/wifiRun(32469): testEnergy: 2.795
06-11 12:57:31.268: D/wifiRun(32469): testBright: 171
06-11 12:57:31.268: D/wifiRun(32469): testEnergy: 36.339
06-11 12:57:31.268: D/wifiRun(32469): testBright: 171
06-11 12:57:31.268: D/wifiRun(32469): testEnergy: 6.289
06-11 12:57:31.268: D/wifiRun(32469): testBright: 171
06-11 12:57:31.273: D/wifiRun(32469): testEnergy: 0.699
06-11 12:57:31.273: D/wifiRun(32469): testBright: 171
06-11 12:57:31.273: D/wifiRun(32469): testEnergy: 13.977
06-11 12:57:31.273: D/wifiRun(32469): testBright: 171