2014-01-24 58 views
0

嘿,我有一個問題,我的android應用程序。我試圖從給定的網址下載文本到可編輯框,但是當我運行應用程序,並按下按鈕,它停止工作。 我檢查了多次,它的問題與jsoup.The設備有互聯網連接。 下面的代碼重命名文件錯誤eclipse java

public void sendMessage(View view) throws IOException { 
    EditText tf = (EditText) findViewById(R.id.editText1); 
    String kupa = tf.getText().toString(); 
    Document doc = Jsoup.connect(kupa).get(); 
    String title = doc.text(); 
    TextView tv = (TextView) findViewById(R.id.textView1); 
    tv.setText(title); 
} 

歡呼傢伙

+0

後的堆棧跟蹤 – turbo

回答

0

在你的onCreate(添加此):

StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); 
StrictMode.setThreadPolicy(policy); 

使用上述作爲臨時解決方案。否則使用線程或asynctask。

定義的AsyncTask象下面這樣:

private class DownloadTask extends AsyncTask { 
protected String doInBackground(Void... params) { 
    EditText tf = (EditText) findViewById(R.id.editText1); 
    String kupa = tf.getText().toString(); 
    Document doc = Jsoup.connect(kupa).get(); 
    String title = doc.text(); 
    return title; 
} 

protected void onPostExecute(String result) { 
    TextView tv = (TextView) findViewById(R.id.textView1); 
    tv.setText(result); 
} } 

調用的任務象下面這樣:

new DownloadTask().execute();