Incident at AsyncTask when working with ListView Adapter
-
In fact, I've set up a caste-based adapter that initiates AsyncTask, in the OnPostExecute method, I'm calling another AsyncTask, who checks out new orders on the server, but before that, he goes to the database and looks at the last number of the order to determine which number to find new ones, and in that place, he's falling. But on the emulsion, I see either a black screen with a mistake:
12-10 16:32:21.921 13500-13507/? E/jdwp﹕ Failed sending reply to debugger: Broken pipe 12-10 16:32:21.921 13500-13507/? D/dalvikvm﹕ Debugger has detached; object registry had 1 entries
Either I see a whole sheet of mistakes and the app is closing. However, there was no standard ArrayAdapter.
12-10 16:26:06.233 10651-10699/com.root.ecoistdemo E/AndroidRuntime﹕ FATAL EXCEPTION: AsyncTask #2 java.lang.RuntimeException: An error occured while executing doInBackground() at android.os.AsyncTask$3.done(AsyncTask.java:299) at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273) at java.util.concurrent.FutureTask.setException(FutureTask.java:124) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307) at java.util.concurrent.FutureTask.run(FutureTask.java:137) at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569) at java.lang.Thread.run(Thread.java:856) Caused by: java.lang.IllegalStateException: Cannot perform this operation because the connection pool has been closed. at android.database.sqlite.SQLiteConnectionPool.throwIfClosedLocked(SQLiteConnectionPool.java:962) at android.database.sqlite.SQLiteConnectionPool.waitForConnection(SQLiteConnectionPool.java:599) at android.database.sqlite.SQLiteConnectionPool.acquireConnection(SQLiteConnectionPool.java:348) at android.database.sqlite.SQLiteSession.acquireConnection(SQLiteSession.java:894) at android.database.sqlite.SQLiteSession.executeForCursorWindow(SQLiteSession.java:834) at android.database.sqlite.SQLiteQuery.fillWindow(SQLiteQuery.java:62) at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:143) at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:133) at android.database.AbstractCursor.moveToPosition(AbstractCursor.java:196) at android.database.AbstractCursor.moveToFirst(AbstractCursor.java:236) at com.root.ecoistdemo.DAO.impl.OrderDAO.getLastId(OrderDAO.java:175) at com.root.ecoistdemo.util.CheckNewOrders.check(CheckNewOrders.java:19) at com.root.ecoistdemo.activity.OrdersActivity$checkNewOrdersOnServer.doInBackground(OrdersActivity.java:156) at com.root.ecoistdemo.activity.OrdersActivity$checkNewOrdersOnServer.doInBackground(OrdersActivity.java:152) at android.os.AsyncTask$2.call(AsyncTask.java:287) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305) at java.util.concurrent.FutureTask.run(FutureTask.java:137) at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569) at java.lang.Thread.run(Thread.java:856)
Both AsyncTask
public class GetOrders extends AsyncTask<String, Void, Boolean> { private OrdersActivity activity;
public GetOrders(OrdersActivity activity) { this.activity = activity; progressDialog = new ProgressDialog(OrdersActivity.this); } protected void onPreExecute() { progressDialog.setMessage("Обновление списка заказов"); progressDialog.show(); } @Override protected Boolean doInBackground(String... arg) { orderList = new OrderDAO(getApplicationContext()).getOrderList(); for (Order order : orderList) { order.setPosition(new OrderPositionDAO(getApplicationContext()).getOrderPositionList(order.getId())); } listadapter = new OrdersListAdapter(OrdersActivity.this, (ArrayList<Order>) orderList); return true; } @Override protected void onPostExecute(final Boolean success) { if (progressDialog.isShowing()) { progressDialog.dismiss(); } if (success){ new checkNewOrdersOnServer().execute() } listView.setAdapter(listadapter); }
}
public class checkNewOrdersOnServer extends AsyncTask<String, Void, Boolean> {
@Override
protected Boolean doInBackground(String... params) {
if (IsOnline.check(getApplicationContext())){
if (CheckNewOrders.check(OrdersActivity.this)){
return true;
}
}else {
return false;
}
return null;
}@Override protected void onPostExecute(Boolean aBoolean) { if (aBoolean == null){ }else { if (aBoolean){ CheckNewOrders.showDialog(OrdersActivity.this); } if (!aBoolean){ IsOnline.showDialog(OrdersActivity.this); } } }
}
-
Okay. Called the second AsyncTask from the method onPostExecute() First AsyncTask into the method onCreate, thus:
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_orders);
new GetOrders(OrdersActivity.this).execute(); new checkNewOrdersOnServer().execute(); ;}
I don't know why, but it worked. If anyone knows what the problem was, please explain why the previous version was a mistake.