小编Man*_*rei的帖子

AsyncTask异常

我是Android开发的初学者,我正在使用我的fisrt应用程序,我遇到了一个问题.我必须下载一些图像投掷互联网,并在活动中显示它们.我有一个UI延迟,直到下载图像,所以我必须使用多线程.

我阅读了更多关于它的内容,我认为最简单的是使用AsyncTask,但我发现了一个异常: Only the original thread that created a view hierarchy can touch its views.

我需要帮助.可以帮助我吗?代码是这样的:

public class Main extends Activity{



protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    Download download = new Download();
    download.execute(null);
}

private class Download extends AsyncTask<String, Void, String>{
    ImageButtonOverloaded[] imgView = new ImageButtonOverloaded[24];
    TextView[] textView = new TextView[24];
    @Override
    protected String doInBackground(String... params) {
        try{

            URL url = null;
            url = new URL(StaticClass.URL_HOST + "front_page_last_games_plaintext.php");
            URLConnection conn = url.openConnection();
            BufferedReader reader …
Run Code Online (Sandbox Code Playgroud)

android exception android-asynctask

3
推荐指数
1
解决办法
207
查看次数

标签 统计

android ×1

android-asynctask ×1

exception ×1