Android:Unable to open stack file

问题描述

我的程序使用get方法用api获取数据。log输出都很正常,但在输出到TextView时报错。

报错如下

06-11 11:20:35.692: E/dalvikvm(253): Unable to open stack trace file '/data/anr/traces.txt': Permission denied

代码如下

geturl="http://v1.itooi.cn/netease/search?keyword="+name.getText()+"&type=song&pagesize=1";
                new Thread(new Runnable() {
                  public void run() {
                      try {
                          URL url = new URL(geturl);
                          HttpURLConnection connection = (HttpURLConnection) url.openConnection();//开启连接
                          connection.connect();//连接服务器

                          if (connection.getResponseCode() == 200) {
                              //使用字符流形式进行回复
                              InputStream is = connection.getInputStream();
                              //读取信息BufferReader
                              BufferedReader reader = new BufferedReader(new InputStreamReader(is));
                              StringBuffer buffer = new StringBuffer();
                              String readLine = "";
                              while ((readLine = reader.readLine()) != null) {
                                  buffer.append(readLine);
                              }
                              is.close();
                              reader.close();
                              connection.disconnect();
                              res=buffer.toString();
                              Log.d("Msg", res);

                              rest.setText(res);
                              }
                      } catch (MalformedURLException e) {
                          e.printStackTrace();
                      } catch (IOException e) {
                          e.printStackTrace();
                      }
                  }

(请不要在意括号匹配,重点看“rest.setText(res);”,我注释掉这句就没错了,这句什么问题?)

1个回答

子线程更新UI,都提示ANR了

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问