このコードを実行すると、アプリがクラッシュします。
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
WebからTextViewにテキストを配置するにはどうすればよいですか?これは、伝記付きの出力を持つPHPスクリプトです。
よろしくお願いします!