私はすべての例を見てきましたが、これはうまくいかないようです。テキストファイルのリモートテキストをAndroidのテキストビューに読み込むにはどうすればよいですか?
これは私の現在のコードです:
あなたのAndroidデバイスがオンラインであり、あなたがINTERNET権限にアプリを許可している、これを試してみてくださいと仮定package hello.android;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class HelloAndroidActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView tv = (TextView) findViewById(R.id.textView1);
try {
// Create a URL for the desired page
URL url = new URL("http://xlradioaustin.com/song/CurrentSong.txt");
// 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)
}
in.close();
tv.setText(str);
} catch (MalformedURLException e) {
tv.setText("mal");
} catch (IOException e) {
tv.setText("io");
}
}
}
を追加した後、あなたのスタックトレースを投稿することができます働いていましたか?正確なエラーが何であるかを知らなくてもソリューションを提供することは困難です。 –