我正在开发一个从SQLite数据库中获取数据的应用程序。我有表格中的数据。当我在模拟器中运行应用程序时,它正在正确地获取数据。但是,当我尝试在设备中进行调试时,不会获取任何数据。游标返回0行。它在模拟器中运行良好。
我有一个按钮单击事件,它触发数据库调用并返回一个arraylist 代码段如下:
f4.setOnClickListener(new OnClickListener()
{
@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
@Override
public void onClick(View v) {
if (Build.VERSION.SDK_INT >= 16) {
f4.setBackground(getResources().getDrawable(
R.drawable.standards_btn_pressed));
} else {
f4.setBackgroundDrawable(getResources()
.getDrawable(R.drawable.standards_btn_pressed));
}
List<ProductModel> pList = new ArrayList<ProductModel>();
db = new DataBaseHelper(getApplicationContext());
pList = db.getData("F4");
showTextFields(pList);
}
});
//getData function
public List<ProductModel> getData(String param) {
SQLiteDatabase db = this.getWritableDatabase();
String[] queryParam = new String[] { param.trim() };
Cursor cursor=null;
try
{
cursor = db.rawQuery(
"select * from FEPAFMACRO WHERE gritsize = ?", queryParam);
}
catch (Exception e) {
e.printStackTrace();
}
List<ProductModel> pList = new ArrayList<ProductModel>();
if (cursor.getCount() != 0) {
if (cursor.moveToFirst()) {
int i = 0;
do {
ProductModel pObj = new ProductModel();
pObj.gritSize = cursor.getString(cursor
.getColumnIndex("gritsize"));
.getColumnIndex("retention"));
pList.add(i, pObj);
i++;
} while (cursor.moveToNext());
}
}
return pList;
}
当我在模拟器中运行它时,它会显示数据。但是,当我在设备中运行时,不会获取任何数据。没错也。日志报告中也没有任何内容