不覆盖AsyncTask的抽象方法doInBackground

不覆盖AsyncTask的抽象方法doInBackground

本文介绍了MainActivity.DownloadWebpageTask不是抽象的,不覆盖AsyncTask的抽象方法doInBackground(字符串...)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 公共类MainActivity延伸活动{    TextView的电视;    @覆盖
    保护无效的onCreate(捆绑savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.activity_main);        电视=(的TextView)findViewById(R.id.data);        串的serviceUrl = - ; //我不能表现出来
        串的serviceKey = - ; //我不能表现出来
        的serviceKey = URLEn coder.en code(的serviceKey);
        字符串strSrch =406;
        字符串strUrl =的serviceUrl + + +的serviceKey与& strSrch =的serviceKey =?+ strSrch;        新DownloadWebpageTask()执行(strUrl);
    }    私有类DownloadWebpageTask扩展的AsyncTask<弦乐,太虚,字符串> {        @覆盖
        保护字符串doInBackgroud(字符串的URL ...){
            尝试{
                返回(字符串)downloadUrl((字符串)网址[0]);
            }赶上(IOException异常五){
                返回下载失败;
            }
        }        保护无效onPostExecute(字符串结果){
            tv.append(结果+\\ n);
            tv.append(=======解析结果========= \\ n);            尝试{
                XmlPullParserFactory工厂= XmlPullParserFactory.newInstance();
                factory.setNamespaceAware(真);
                XmlPullParser XPP = factory.newPullParser();                xpp.setInput(新StringReader(结果));
                INT EVENTTYPE = xpp.getEventType();
                布尔BSET = FALSE;
                而(EVENTTYPE!= XmlPullParser.END_DOCUMENT){
                    如果(EVENTTYPE == XmlPullParser.START_DOCUMENT){
                        ;
                    }否则如果(EVENTTYPE == XmlPullParser.START_TAG){
                        字符串TAG_NAME = xpp.getName();
                        如果(tag_name.equals(busRouteNm)|| tag_name.equals(busRouteId))
                            BSET =真;
                    }否则如果(EVENTTYPE == XmlPullParser.TEXT){
                        如果(BSET){
                            字符串内容= xpp.getText();
                            tv.append(内容+\\ n);
                            BSET = FALSE;
                        }
                    }否则如果(EVENTTYPE == XmlPullParser.END_TAG){
                        ;
                    }
                    EVENTTYPE = xpp.next();
                }
            }赶上(例外五){
                tv.setText(e.getMessage());
            }
        }        私人字符串downloadUrl(字符串myurl)抛出IOException            HttpURLConnection的康恩= NULL;
            尝试{
                网址URL =新的URL(myurl);
                康恩=(HttpURLConnection类)url.openConnection();
                BUF的BufferedInputStream =新的BufferedInputStream(conn.getInputStream());
                的BufferedReader bufreader =新的BufferedReader(新的InputStreamReader(BUF,UTF-8));
                串线= NULL;
                字符串页=;
                而((行= bufreader.readLine())!= NULL){
                    网页+ =行;
                }
                返回页面;
            } {最后
                conn.disconnect();
            }
        }
    }}

私有类DownloadWebpageTask扩展的AsyncTask
此行有错误:

解决方案

Typo in method name. Change

protected String doInBackgroud

to

protected String doInBackground

这篇关于MainActivity.DownloadWebpageTask不是抽象的,不覆盖AsyncTask的抽象方法doInBackground(字符串...)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 12:49