运行此代码时,我的应用程序崩溃:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_biografie);
setTitle("Biografie");
try {
// Create a URL for the desired page
URL url = new URL("http://xxx.nl/api/biografie.php?dataid=998");
// Read all the text returned by the server
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
String str;
while ((str = in.readLine()) != null) {
// str is one line of text; readLine() strips the newline character(s)
TextView text = (TextView)findViewById(R.id.biografieText);
text.setText(str);
}
in.close();
} catch (MalformedURLException e) {
} catch (IOException e) {
}
}
这是我的 Logcat 输出:
I/Process(30127):发送信号。PID:30127 SIG:9
我该怎么做才能将网络上的文本放入 TextView?这是一个 PHP 脚本,输出带有传记。
在此致谢!