我创建了一个方法,以请求的SQLite的结果存储在表方法,该方法返回0
public ArrayList <String> getProductName(double idcat)
{
ArrayList <String> tab = new ArrayList <String>();
try
{
Cursor c = null;
c = database.rawQuery("SELECT " + COL_PRODUCT_NAME + " FROM "
+ TABLE_PRODUCT + " WHERE " + COL_CATEGORY + "= '" + idcat + "'", null);
for(int i=0;i<c.getCount();i++)
{
tab.add(c.getString(c.getColumnIndex(COL_PRODUCT_NAME)));
c.moveToNext();
}
c.close();
}
catch(Exception e)
{
e.printStackTrace();
}
return tab;
}
我想在此表中元素的个数,所以我把这个:
ArrayList <String> tab = new ArrayList <String>();
TextView tv = new TextView(this);
tab=db.getProductName(1);
int n =tab.size();
tv.setText("n=" +n);
但是,当我编译我的应用程序,n得到0! 我想知道如果我的方法正确与否
那时你有没有对数据库的开放连接? – Rarw
更改'e.printStackTrace();'抛出新的RuntimeException(e);'知道或读取日志。 –
从数据库读取数据时是否收到异常? – arjoan