2013-10-06 1 views
0

"JSOUP 쿼리를 구현하려고하는데"doc을 확인할 수 없음 "및"doc을 변수로 해석 할 수 없음 "이라는 오류가 발생합니다. 내가 사용하기 전에 doc을 호출해야한다는 것을 안다. 아직 어떻게해야할지 모르겠다. JSOUP을 사용하여 파서를 만드는 것은 처음이다. - 꽤 간단하다고 확신한다. - 빠른 포인터가 필요하다. .JSOUP - doc을 확인할 수없고 변수로 진단 할 수 없습니다.

public class MainActivity extends Activity { 

    TextView tv; 
    String url = "http://microsoft.com"; 
String tr; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     tv = (TextView) findViewById(R.id.TextView01); 
     new MyTask().execute(url); 
    } 

    private class MyTask extends AsyncTask<String, Void, String> { 
     ProgressDialog prog; 
     String title = ""; 

     @Override 
     protected void onPreExecute() { 
      prog = new ProgressDialog(MainActivity.this); 
      prog.setMessage("Loading...."); 
      prog.show(); 
     } 

     @Override 
     protected String doInBackground(String... params) { 
      try { 
        doc = Jsoup.connect(params[0]).get(); 
        Element tableElement = doc.select(".datagrid").first(); 

        Elements tableRows = tableElement.select("tr"); 
        for (Element row : tableRows) { 
         Elements cells = row.select("td"); 
         if (cells.size() >0) { 
          System.out.println(cells.get(0).text()+"; "+cells.get(1).text()+"; "+cells.get(2).text()+"; "+cells.get(3).text()); 
         } 
        }} catch (IOException e) { 
       e.printStackTrace(); 
      } 
      return title; 
     } 




     @Override 
     protected void onPostExecute(String result) { 
      super.onPostExecute(result); 
      prog.dismiss(); 
      tv.setText(result); 
     } 
    } 
} 
+0

당신은 결코 doc 객체를 만들지 않습니다. 필드로 작성하고 메소드에서 초기화하거나 로컬 변수로 작성하십시오. 나중에 메서드를 사용하지 않는 한 나중에 가장 적합 할 것입니다. –

+0

이 메서드 외부에서 사용하는 방법을 계획하고 있습니다 ... 어떻게 필드로 인스턴스화 할 수 있을까요? (답변을 답장으로 게시 할 수 있으면 받아 들일 수 있습니다.) – HelloMojo

답변

0

선언되지 않은 변수를 사용하려고합니다. 이미 완료 한대로

TextView tv; 

을 선언해야합니다.

Document doc; 

다음 패키지 org.jsoup.nodes.Document을 가져 오는 것을 잊지 마십시오.

관련 문제