RuntimeException的:内螺纹已经不叫尺蠖prepare无法创建处理器() [英] RuntimeException: Can't create handler inside thread that has not called Looper.prepare()

查看:176
本文介绍了RuntimeException的:内螺纹已经不叫尺蠖prepare无法创建处理器()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个code时的AsyncTask的问题是,当我执行了几次就与此异常崩溃:RuntimeException的:只有一条环线可以每个线程创建

I've got a code with an ASyncTask and the problem is that when I execute it several times it crashes with this exception: RuntimeException: Only one Looper may be created per thread

但后来我读过这样的: http://stackoverflow.com/a/7781280/869180 和我想起我在过去类似的错误,这是关系到用户界面的东西(一个ProgressDialog在我的情况),在AsyncTask的创建。

But then I've read this: http://stackoverflow.com/a/7781280/869180 and I remembered that I had a similar error in the past and it was related to the UI stuff (a ProgressDialog in my case) created in the ASyncTask.

于是,我脱掉了所有的UI东西从AsyncTask的,我取出活套prepare过,以避免RuntimeException的,但知道我得到这样的:

So I took off all the UI stuff from the ASyncTask and I removed Looper.prepare too, to avoid that RuntimeException, but know I'm getting this:

12-21 00:34:17.363: W/System.err(18658): java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
12-21 00:34:17.371: W/System.err(18658):    at android.os.Handler.<init>(Handler.java:121)
12-21 00:34:17.371: W/System.err(18658):    at android.app.Activity.<init>(Activity.java:683)
12-21 00:34:17.371: W/System.err(18658):    at com.konex.Alaves.Parser.<init>(Parser.java:29)
12-21 00:34:17.371: W/System.err(18658):    at com.konex.Alaves.News$LoadNews.doInBackground(News.java:131)

下面是code:

private class LoadNews extends AsyncTask<String, Void, Void> 
{
    private List<Noticia> data = new ArrayList<Noticia>();

    @Override
    protected void onPreExecute() {
        m_dialog.show();
    }

    @Override
    protected Void doInBackground(String... url) {
        try {

//          Looper.myLooper();
//          Looper.prepare();
            Parser parser = new Parser(url[0], url[1]);
            data = parser.run();

           } catch (Exception e) { 
               e.printStackTrace();
           }
        return null;
    }

@Override
    protected void onPostExecute(Void result) {

            m_dialog.dismiss();

        if(data !=null )                
            showNewContent(data);
    }
}

我敢肯定,我失去了一些东西还是我做了坏事,但我不能够在任何地方找到它。

I'm sure I'm missing something or I am doing something bad, but I'm not able to find it anywhere.

多谢

推荐答案

由于堆栈跟踪告诉你,你的问题,从 Parser.java 行29起源,在解析器初始化。你会注意到,这是不是源$ C ​​$ c您包括在这里,这是 LoadNews

As the stack trace tells you, your problem originates from line 29 of Parser.java, in the Parser initializers. You will note that this is not the source code you included here, which is for LoadNews.

根据堆栈跟踪的preceding线,或者:

Based on the preceding line of the stack trace, either:

  • 解析器继承的活动

解析器正在试图实例化一个活动

Parser is trying to instantiate an Activity

这些都不是可能的。

这篇关于RuntimeException的:内螺纹已经不叫尺蠖prepare无法创建处理器()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆