java - HttpPost : InputDispatcher: "Channel is unrecoverably broken and will be disposed!" on Nexus 7

标签 java android http-post channel socketchannel

在 Nexus 7 (4.3) 上,而不是在我的旧设备 LG Optimus 3d (Android 2.2) 上, 当我执行 HttpPost 时,我得到了这个

E/InputDispatcher: channel '4273f7b0 ... MainActivity(服务器)'〜 channel 已不可恢复地损坏,将被处置!

人们提到了可能的内存泄漏。看 **。但是,当我尝试 HttpPost 时,启动时立即出现此问题。是否仍然可能存在内存泄漏?

这是我执行 HttpPost 的方法:

public void server_addUserGetId()
{
    String url = GS.baseUrl() + "/users";
    HttpPost theHttpPost = new HttpPost(url);

    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
    nameValuePairs.add(new BasicNameValuePair("dId", s_UserInfo.getInstance().m_device_id ));
    try {
        theHttpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    HttpPostAsync theHttpPostAsync = new HttpPostAsync(new OnPostExecuteHandler() {
        @Override
        public void handlePostExecute(Object oHttpResponse) {
            HttpResponse theHttpResponse = (HttpResponse) oHttpResponse;
            JSONObject jo = GS.getJSONObject(theHttpResponse.getEntity());
            try {
                s_UserInfo.getInstance().m_user_id = jo.getString("_id");
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    });
    theHttpPostAsync.execute(theHttpPost);
    return;
}

这是我的 HttpPostAsync 任务:

public class HttpPostAsync extends AsyncTask<HttpPost, Integer, HttpResponse>
{
    private HttpPost m_HttpPost;
    private HttpResponse m_HttpResponse;

    private OnPostExecuteHandler m_OnPostExecuteHandler;
    public HttpPostAsync(OnPostExecuteHandler listener)
    {
        m_OnPostExecuteHandler = listener;
    }

    protected HttpResponse doInBackground(HttpPost ... args)
    {
        m_HttpPost = args[0];
        if(GS.dl>5) Log.d("GRA: HttpPostAsync", "doInBackground: Thread.currentThread().getId()=" + Thread.currentThread().getId());
        m_HttpResponse = visit(m_HttpPost);
        return m_HttpResponse;
    }

    protected void onProgressUpdate(Integer... progress) {
    }

    protected void onPostExecute(Long result) {
        if(GS.dl>5) Log.d("GRA: HttpPostAsync", "onPostExecute: Thread.currentThread().getId()=" + Thread.currentThread().getId());
        if(GS.dl>5) Log.d("GRA: HttpPostAsync", "onPostExecute: result=" + result);
        //if(GS.dl>5) Log.d("GRA: HttpPostAsync", "onPostExecute: m_HttpEntity="+m_HttpEntity);
        m_OnPostExecuteHandler.handlePostExecute(m_HttpResponse);
    }

    public HttpResponse visit(HttpPost theHttpPost)
    {
        HttpResponse response = null;
        try {
            // Create a new HttpClient and Post Header
            HttpClient httpclient = new DefaultHttpClient();
            // Execute HTTP Post Request
            response = httpclient.execute(theHttpPost);
        } catch (IOException e) {
            e.printStackTrace();
            Log.d("HttpPostAsync.java", "IOException e=" + e);
            // TODO Auto-generated catch block
        }
        return response;
    }
}

有什么想法吗?

我读到了一个SO答案*,它可能与ArrayList初始化有关,所以我也尝试过像这样初始化,在ArrayList中使用1,但问题仍然存在:

List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);

*:所以答案并不完全相关/帮助: App has stopped working Android

** 与内存泄漏有关吗? http://android-developers.blogspot.com/2011/03/memory-analysis-for-android.html

最佳答案

这是由于某些代码而导致的内存链接的常见问题。 看blog post在开发者文档中进行追踪。

关于java - HttpPost : InputDispatcher: "Channel is unrecoverably broken and will be disposed!" on Nexus 7,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22758482/

相关文章:

android - 云消息和安卓

android - 线程更新不适用于选定的客户端

asp.net-mvc-3 - 发回 View 后值不会改变?

java - 使用 JSONAssert 检查 JSON 数组中是否存在某个项目

带有类元素的java队列

java - 如何将数据库中的数据显示到旋转器中?

android - 为单个数据库列创建一个在selectionArgs中包含多个项目的游标

http-post - 如何从 ASP.NET Web API(POST 或 PUT)调用获取 httppostedfile?

mysql - 从React表单发布到我的后端API时出错

java - 使用 Java 中的双倍长度 3DES key 进行加密并生成 16 字节数组密码