2014-11-19 2 views
0

JSOUP을 사용하여 url에서 일부 html을 가져 오는 앱을 만들고 있습니다. 단일 URL의 구문 분석은 올바르게 작동하지만 둘 이상의 URL을 사용할 때마다 작동하지 않습니다. 이 내 코드입니다 :jsoup가 여러 if 문과 함께 asynctask 내부에서 올바르게 작동하지 않습니다.

public class Test extends AsyncTask<String, Void, Void> { 
    String desc; 
    String u; 
    String key; 

    String xy; 

    public Test(Activity contex, String key) { 
     this.mContex = contex; 
     this.key = key; 
    } 

    Activity mContex; 

    @Override 
    protected void onPreExecute() { 
     super.onPreExecute(); 
     mProgressDialog = ProgressDialog 
       .show(getActivity(), "", null, true); 
     mProgressDialog.setMessage("Loading..."); 
     mProgressDialog.setIndeterminate(true); 
     mProgressDialog.show(); 
     xy = key; 

    } 

    @Override 
    protected Void doInBackground(String... params) { 
     if (xy == "abcd") { 
      String url = "http://....."; 
      try { 

       Document document = Jsoup.connect(url).get(); 
       Elements myin = document.select("div.content-wrap"); 
       desc = myin.text().toString(); 


      } catch (IOException e) { 
       e.printStackTrace(); 
      } 

     } 
     return null; 

    } 

    @Override 
    protected void onPostExecute(Void result) { 
     respText.setText(desc); 

     mProgressDialog.dismiss(); 

    } 

} 

키가 I 8 개를 추가 할 스위치 case.And를 사용하여 AsyncTask를 위해 전송되는 경우 내 문제는 '내가없이이 프로젝트를 실행할 때마다하는 것이 무엇 doInbackground

에 문 if 문은 작동하지만 'if (xy == "abcd")'를 추가하면 작동하지 않습니다. 오류가 없으므로 이것을 파악할 수 없습니다.

+0

사용'같음을 문자열을 비교하는 데 사용 xy.equals("abcd") 작동하지 않습니다 if(xy=="abcd") 사용. – Luksprog

+0

@ Luksprog 그래, 그게 ... 어리석은 나는 ..... –

답변

0
if(xy.equals("abcd")){ 
    //do stuff 
} 

== operator compares memory addresses you should use `.equals()` when working with strings. 
0

자바()`대신`==`의

관련 문제