在你們讓它重複之前,我已經在任何地方搜索過它,而且我被困在了一個需要你的專業知識的地步。SearchView與GridView中的Postexecute方法
我在doInBackground方法中調用我的數據,並將值存儲在SimpleAdapter中,並在postExecute方法中,我將適配器分配給我的gridView。而且在PostExecute中,我有一個可以過濾我的適配器的searchView方法。
現在,當我在搜索中按任何字母我的應用程序崩潰與NullPointerException異常,如果相同的代碼我運行在同一個線程上而不做一個AsyncTask我沒有得到這個錯誤。這裏是我的DoInBackground代碼:
protected Void doInBackground(Void... voids) {
try{
connect = CONN(un, passwords, db, ip);
String StoredProc = "{call pro.DocumentDelivery_inst_update_delete(?,?)}";
callableStatement=connect.prepareCall(StoredProc);
callableStatement.setString(1, "Select");
callableStatement.setString(2, MainActivity.usernam);
rs = callableStatement.executeQuery();
while(rs.next()){
Map<String,String> datanum = new HashMap<String, String>();
datanum.put("B",rs.getString("FullName"));
datanum.put("C",rs.getString("Name"));
datanum.put("D",rs.getString("DocumentType"));
datanum.put("A",rs.getString("Id"));
datanum.put("E",rs.getString("TaskType"));
datanum.put("F",rs.getString("Comments"));
datanum.put("G",rs.getString("Tasktime"));
datanum.put("H",rs.getString("Priority"));
datanum.put("I",rs.getString("Telephone"));
data.add(datanum);
}
String [] from = {"A","B","C","D","E","F","G","H","I"};
int[] views = {R.id.doc_grid_t4,R.id.doc_grid_t1, R.id.doc_grid_t2,R.id.doc_grid_t3,R.id.doc_grid_t5,R.id.doc_grid_t6,R.id.doc_grid_t7,R.id.doc_grid_t8,R.id.doc_grid_t9};
ADA = new SimpleAdapter(document_Pro_List.this,data,R.layout.custom_pro_document_view, from, views);
synchronized (this) {
int counter = 0;
while(counter<=4){
this.wait(100);
counter++;
publishProgress(counter*25);
}
}
}
catch (InterruptedException | SQLException e){
e.printStackTrace();
}
return null;
}
,這是我postExecute方法的代碼:
protected void onPostExecute(Void result){
sv = (SearchView) findViewById(R.id.searchView);
progressDialog.dismiss();
gridView.setAdapter(ADA);
sv.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
return false;
}
@Override
public boolean onQueryTextChange(String query) {
ADA.getFilter().filter(query);
//ADA.notifyDataSetChanged();
return false;
}
});
}
注:此刻我拿出這個
Map<String,String> datanum = new HashMap<String, String>();
out while循環我停止得到NullPointerException但是這不能幫助我,因爲它然後重複第1個d從數據庫到所有下一個數據庫。 另外我知道我應該和WebAPI一起工作,並且我正在並肩努力。 請幫我解釋如何刪除此異常。
THANK YOU