Java TimerTask
天蓬老师
天蓬老师 2017-04-17 14:18:53
0
1
249
public static void main(String[] args) throws Exception    {  


    Timer timer = new Timer();
    timer.schedule(new TimerTask() { 

   Document doc = Jsoup.connect("http://www.oschina.net/").get();
    public void run(){

    Elements t = doc.select("table");

    String linkText = t.text();      
    System.out.println(linkText);
   }

    },1000,5000);
}  

为什么上面的代码编译正常,下面的就不行了?

public static void main(String[] args) throws Exception    {  


    Timer timer = new Timer();
    timer.schedule(new TimerTask() { 


    public void run(){
    Document doc = Jsoup.connect("http://www.oschina.net/").get();
    Elements t = doc.select("table");

    String linkText = t.text();      
    System.out.println(linkText);
   }

    },1000,5000);
}  

这一句移了一个位置
Document doc = Jsoup.connect("http://www.oschina.net/").get();

编译错误:

Exception in thread "Timer-0" java.lang.Error: Unresolved compilation problem:
Unhandled exception type IOException
at bitcoin.aaa$1.run(aaa.java:25)
at java.util.TimerThread.mainLoop(Unknown Source)
at java.util.TimerThread.run(Unknown Source)

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!