处理程序{40664220}在死线程上向处理程序发送消息

时间:2014-11-25 06:32:37

标签: java android multithreading android-asynctask android-handler

我收到此错误,我的代码是,任何人都可以帮助

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
        new FetchAddressTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, Constants.USER_CURRENT_LOCATION);
    else
        new FetchAddressTask().execute(Constants.USER_CURRENT_LOCATION);


    class FetchAddressTask extends AsyncTask<LatLng, String, String> {
    @Override
    protected void onPreExecute() {
        // showDialog();
        // showMyDialog();
        DialogHelper.showTrasparentDialog(EnterBikeInfoActivity.this);
        super.onPreExecute();
    }

    @Override
    protected String doInBackground(LatLng... latLngs) {

        String result = getCurrentLocationViaJSON(latLngs[0].latitude, latLngs[0].longitude);
        if (result == null)
            result = "";
        return result;
    }

    @Override
    protected void onPostExecute(String result) {
        if (result == null || result.length() == 0) {
            DialogHelper.showDialogMessage(BikeApp.getInstance(), "Unable to retrieve the address.");
        } else {
            addressEditText.setText(result);
        }

        DialogHelper.dismissTransparentDialog();
        super.onPostExecute(result);
    }
}


 public String getCurrentLocationViaJSON(double lat, double lng) {
    JSONObject jsonObj = getLocationInfo(lat, lng);
    Log.i("JSON string =>", jsonObj.toString());
    String currentLocation = "testing";
    // String street_address = null;
    // String postal_code = null;
    try {
        String status = jsonObj.getString("status").toString();
        Log.i("status", status);
        if (status.equalsIgnoreCase("OK")) {
            JSONArray results = jsonObj.getJSONArray("results");
            int i = 0;
            Log.i("i", i + "," + results.length()); // TODO delete this
            JSONObject r0 = results.getJSONObject(i);
            String v = r0.getString("formatted_address");
            currentLocation = v;
            Log.i("JSON Geo Locatoin =>", currentLocation);
            return currentLocation;
        }
    } catch (JSONException e) {
        Log.e("testing", "Failed to load JSON");
        e.printStackTrace();
    }
    return "";
}

getLocationInfo(lat,lng); funtion从http请求中获取地址信息,我的流进入FetchAddressTask doInBackground,地址正确,但是当它返回地址时,它会给我这个错误信息。

11-25 11:20:01.746: W/MessageQueue(2593): Handler{40664220} sending message to a Handler on a dead thread
11-25 11:20:01.746: W/MessageQueue(2593): java.lang.RuntimeException: Handler{40664220} sending message to a Handler on a dead thread
11-25 11:20:01.746: W/MessageQueue(2593):   at android.os.MessageQueue.enqueueMessage(MessageQueue.java:196)
11-25 11:20:01.746: W/MessageQueue(2593):   at android.os.Handler.sendMessageAtTime(Handler.java:457)
11-25 11:20:01.746: W/MessageQueue(2593):   at android.os.Handler.sendMessageDelayed(Handler.java:430)
11-25 11:20:01.746: W/MessageQueue(2593):   at android.os.Handler.sendMessage(Handler.java:367)
11-25 11:20:01.746: W/MessageQueue(2593):   at android.os.Message.sendToTarget(Message.java:349)
11-25 11:20:01.746: W/MessageQueue(2593):   at android.os.AsyncTask$3.done(AsyncTask.java:214)
11-25 11:20:01.746: W/MessageQueue(2593):   at java.util.concurrent.FutureTask$Sync.innerSet(FutureTask.java:253)
11-25 11:20:01.746: W/MessageQueue(2593):   at java.util.concurrent.FutureTask.set(FutureTask.java:113)
11-25 11:20:01.746: W/MessageQueue(2593):   at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:311)
11-25 11:20:01.746: W/MessageQueue(2593):   at java.util.concurrent.FutureTask.run(FutureTask.java:138)
11-25 11:20:01.746: W/MessageQueue(2593):   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
11-25 11:20:01.746: W/MessageQueue(2593):   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
11-25 11:20:01.746: W/MessageQueue(2593):   at java.lang.Thread.run(Thread.java:1019)

0 个答案:

没有答案