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