package info.testing;
import java.io.IOException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.webkit.WebView;
import android.widget.Toast;
public class SoupActivity extends Activity {
private static final String TAG = "SoupActivity";
private static final String DATA = null;
private String data = null;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
if(savedInstanceState != null)
{
data = savedInstanceState.getString(DATA);
showResults();
}
else
{
parsePage();
}
}
protected void parsePage(){
Document doc = null;
try {
doc = Jsoup.connect("http://www.mydata.html").get();
Toast.makeText(this, R.string.success, Toast.LENGTH_SHORT).show();
} catch (IOException e) {
Toast.makeText(this, R.string.error, Toast.LENGTH_SHORT).show();
}
Elements rows = doc.select("tr[class]");
data = "<table>" + rows.toString() + "</table>";
showResults();
}
protected void showResults(){
WebView web = (WebView)findViewById(R.id.web);
web.loadData(data, "text/html", "utf-8");
}
@Override
public void onSaveInstanceState(Bundle savedInstanceState){
savedInstanceState.putString(DATA, data);
super.onSaveInstanceState(savedInstanceState);
}
@Override
public void onRestoreInstanceState(Bundle savedInstanceState){
if(savedInstanceState != null)
{
data = savedInstanceState.getString(DATA);
}
super.onRestoreInstanceState(savedInstanceState);
}
}
的Flash/Flex開發者在這裏開始獲得在Android開發關閉,我必須承認,我喜歡它,到目前爲止,但很明顯,花費很長的時間來解決的事情,爲什麼會發生他們的方式。的Android - 應用力在沒有互聯網連接
所以我遇到的問題是我的應用程序崩潰沒有互聯網連接 - 應用程序(process.testing)意外停止。這隻發生在沒有互聯網連接的情況下,如果有的話可以完美地工作。我的代碼訪問Internet的唯一部分是在try catch塊中,任何人都可以看到我在做什麼錯誤,或者當沒有可用的Internet連接時如何處理錯誤?
是的,當然,有點小學生的錯誤,如果我更熟悉調試器,我會抓住那一個,謝謝。 – Neil
那麼下一次呢... – MByD