解决方案 »

  1.   

    你哪放线程中了?
    new Thread(new Runable(){
    /*联网获取数据*/
    }).start();
      

  2.   


    我new Runable(){}这个方法不是在线程中?
      

  3.   

     boolean android.view.View.postDelayed(Runnable action, long delayMillis)
    Causes the Runnable to be added to the message queue, to be run after the specified amount of time elapses. The runnable will be run on the user interface thread.Parameters:
    action The Runnable that will be executed.
    delayMillis The delay (in milliseconds) until the Runnable will be executed.
    Returns:
    true if the Runnable was successfully placed in to the message queue. Returns false on failure, usually because the looper processing the message queue is exiting. Note that a result of true does not mean the Runnable will be processed -- if the looper is quit before the delivery time of the message occurs then the message will be dropped.
    See Also:
    post
    removeCallbacks
      

  4.   


    我new Runable(){}这个方法不是在线程中?
    runable是一个以过程方法函数,你使用Handle.postdelay;是指在一定时间之后去执行这个方法!thread才是线程! 你按照1楼的写法就可以了
      

  5.   

    android里面好像还要设置handler处理类
      

  6.   

    android 自带 的AsyncTask 这个方法,可以试试
      

  7.   

    像post这些方法一般都是放到主线程执行的
      

  8.   

    postdelay()方法中的2个参数,用你这个不行呀,
      

  9.   

    有几种方式解决,第一个是 new Thread(),第二个AsycnTask. 你现在虽然是有run方法。但是你是使用postdelay. 这个方法应该是在主线程运行的。所以才会出这个异常
      

  10.   

    android 4.0以后网络操作不能再主线程
      

  11.   

    handler.post(Runnable())及handler.post
      

  12.   

    handler.postdelay()都是运行在ui线程中
      

  13.   


    1)网络代码不能在GUI主线程中执行。
    2)楼主错误在于:XXX.postDelayed(new Runnable(){}),虽然new Runnable(){网络代码} ,但这不是一个线程,只是一个实现了Runnable接口的对象。然后:这个网络代码是通过postDelayed()方法还是提交给GUI主线程来做的。这就是错误的根源。
      

  14.   

    楼上基本上都说对了的,你可以通过Thread.currentThread().getId();去看你runnable里面的id和外面的UI线程的ID是否一样。就确切知道你没有将耗时的网络操作放到非主线程中去工作了。