我正在写一个警报对话框,里面有一个微调框,用于显示SQLiteDatabase中的项目。但是,当执行SQLiteDatabase.query()时,logcat会给我一个异常,该异常将在下面粘贴。
注释查询语句后,它可以正常工作。警报窗口可以很好地显示微调器中没有任何信息。因此,问题应该出在查询执行上。
//Triggered by android:onClick. 'diancai' means order.
public void diancai(View view){
//Create AlertDialog, set two buttons.
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("点菜");
builder.setPositiveButton("确定", listener);
builder.setNegativeButton("取消", null);
//inflate view
View inflateViewDiancai = View.inflate(this, R.layout.diancai, null);
builder.setView(inflateViewDiancai);
//Set adapter for spinner.
Spinner spinner = findViewById(R.id.spinner1);
MenuAdapter menuAdapter = new MenuAdapter();
spinner.setAdapter(menuAdapter);
//Query dishes from SQLiteDatabase
new Thread(){
@Override
public void run() {
super.run();
menuList = dbAdapter.query(); //***problem here***
}
}.start();
menuAdapter.notifyDataSetChanged();
builder.create().show();
}
//query method as below:
public List<Menu> query() {
open();
String[] columns = {ID, TID, NAME, PRICE, DESCRIPTION};
//SQLiteDatabase.query(params...); Query the given table, returning a cursor over the result set.
Cursor cursor = database.query(TABLE_NAME, columns, null, null, null, null, null); //LogCat shows problems here.
List<Menu> list = new ArrayList<>();
int count = cursor.getCount();
for (int i = 0; i < count; i++) {
cursor.moveToPosition(i);
int id = cursor.getInt(0);
int tid = cursor.getInt(1);
String name = cursor.getString(2);
int price = cursor.getInt(3);
String desc = cursor.getString(4);
Menu menu = new Menu();
menu.setId(id);
menu.setTid(tid);
menu.setName(name);
menu.setPrice(price);
menu.setDesc(desc);
list.add(menu);
}
database.close();
return list;
}
LogCat信息:
2019-05-24 17:44:47.294 2648-12884/com.google.android.googlequicksearchbox:search E/EntrySyncManager: Cannot determine account name: drop request(???????????? what's this)
2019-05-24 17:44:47.294 2648-12884/com.google.android.googlequicksearchbox:search E/NowController: Failed to access data from EntryProvider. ExecutionException.
java.util.concurrent.ExecutionException: com.google.android.apps.gsa.sidekick.main.h.n: Could not complete scheduled request to refresh entries. ClientErrorCode: 3
at com.google.common.util.concurrent.d.eA(SourceFile:85)
at com.google.common.util.concurrent.d.get(SourceFile:23)
at com.google.common.util.concurrent.l.get(SourceFile:2)
at com.google.android.apps.gsa.staticplugins.nowstream.b.a.be.cbB(SourceFile:49)
at com.google.android.apps.gsa.staticplugins.nowstream.b.a.be.cbA(SourceFile:181)
at com.google.android.apps.gsa.staticplugins.nowstream.b.a.bh.run(Unknown Source:2)
at com.google.android.apps.gsa.shared.util.concurrent.at.run(SourceFile:4)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:458)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:458)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at com.google.android.apps.gsa.shared.util.concurrent.b.g.run(Unknown Source:4)
at com.google.android.apps.gsa.shared.util.concurrent.b.aw.run(SourceFile:4)
at com.google.android.apps.gsa.shared.util.concurrent.b.aw.run(SourceFile:4)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:764)
at com.google.android.apps.gsa.shared.util.concurrent.b.i.run(SourceFile:6)
Caused by: com.google.android.apps.gsa.sidekick.main.h.n: Could not complete scheduled request to refresh entries. ClientErrorCode: 3
at com.google.android.apps.gsa.staticplugins.nowstream.b.a.ar.az(Unknown Source:4)
at com.google.common.util.concurrent.q.ap(SourceFile:7)
at com.google.common.util.concurrent.p.run(SourceFile:32)
at com.google.common.util.concurrent.bt.execute(SourceFile:3)
at com.google.common.util.concurrent.d.b(SourceFile:275)
at com.google.common.util.concurrent.d.addListener(SourceFile:135)
at com.google.common.util.concurrent.p.b(SourceFile:3)
at com.google.android.apps.gsa.shared.util.concurrent.h.a(SourceFile:16)
at com.google.android.apps.gsa.shared.util.concurrent.h.a(SourceFile:13)
at com.google.android.apps.gsa.staticplugins.nowstream.b.a.be.cbB(SourceFile:47)
at com.google.android.apps.gsa.staticplugins.nowstream.b.a.be.cbA(SourceFile:181)
at com.google.android.apps.gsa.staticplugins.nowstream.b.a.bh.run(Unknown Source:2)
at com.google.android.apps.gsa.shared.util.concurrent.at.run(SourceFile:4)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:458)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:458)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at com.google.android.apps.gsa.shared.util.concurrent.b.g.run(Unknown Source:4)
at com.google.android.apps.gsa.shared.util.concurrent.b.aw.run(SourceFile:4)
at com.google.android.apps.gsa.shared.util.concurrent.b.aw.run(SourceFile:4)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:764)
at com.google.android.apps.gsa.shared.util.concurrent.b.i.run(SourceFile:6)
如果您需要什么,我会补充。赞赏。