我找不到适合我的问题的标题。这就是问题所在......在syso
'ing 中的语句之后,它应该使用 中的语句getData()
打印游标中的值,。但是,事实并非如此。没有例外和错误。我还保留了我在 LogCat 中获得的输出。有人可以帮助我,为什么第一次打印后没有输出。cMainTable
displayDataForMainTable()
try {
pm = new PortfolioManager(this);
cMainTable = pm.getData("mainTable");
if (cMainTable.equals(null)) {
System.out.println("Null is returned");
}
displayDataForMainTable(cMainTable);
}
catch (Exception e) {
System.out.println("problem at Oncreate Method");
}
getData()
方法:
public Cursor getData(String string) {
System.out.println("Getting Data for Table " + string);
c = sqlDB.rawQuery("select * from " + string, null);
return c;
}
displayDataForMainTable()
方法:
private void displayDataForMainTable(Cursor c2) {
try {
if (c2 != null) {
if (c2.getCount() > 0) {
c2.moveToFirst();
do {
String SNo = c2.getString(c2.getColumnIndex("scriptnumber"));
String SName = c2.getString(c2.getColumnIndex("scriptname"));
int quant = Integer.parseInt(c2.getString(c2.getColumnIndex("totalquantity")));
double avg = Double.parseDouble(c2.getString(c2.getColumnIndex("averageprice")));
double cur = Double.parseDouble(c2.getString(c2.getColumnIndex("currentprice")));
double log = Double.parseDouble(c2.getString(c2.getColumnIndex("lossorgain")));
System.out.println("Inserted Values are ::: " + SNo
+ " " + SName + " " + String.valueOf(quant)
+ " " + String.valueOf(avg) + " "
+ String.valueOf(cur) + " "
+ String.valueOf(log));
} while (c2.moveToNext());
}
}
else {
System.out.println("Cursor c2 is Empty");
}
} catch (Exception e) {
System.out.println("Exception in displayDataForMainTable");
}
}
输出
01-18 11:02:27.523: D/dalvikvm(468): GC_EXTERNAL_ALLOC freed 47K, 53% free 2567K/5379K, external 2090K/2137K, paused 45ms
01-18 11:02:33.983: I/System.out(468): Getting Data for Table mainTable
01-18 11:02:36.584: W/KeyCharacterMap(468): No keyboard for id 0
01-18 11:02:36.584: W/KeyCharacterMap(468): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
编辑 1 ::: 我已getData()
按照 Nasser 的建议进行了修改,但输出保持不变..
public Cursor getData(String string) {
System.out.println("Getting Data for Table "+string);
String table = string;
sqlDB = getReadableDatabase();
c = sqlDB.query(table, null, null, null, null, null, null);
//c = sqlDB.rawQuery("select * from "+string, null);
return c;
}
正如我所读到的,传递null
给列(第二个参数)将返回所有行。如果这是正确的,那么结果是一样的。