URLの内容を読み込もうとしています。BufferedReaderの初期化により、クラッシュが発生し続けます。
人々の解決策を調べてみましたが、何をしてもこのエラーが発生します。
これが私のコードです:
try {
String sUrl = "http://www.google.com";
System.out.println("About to create URL.");
URL url = new URL(sUrl);
System.out.println("Created URL");
System.out.println("About to create URLConnection");
URLConnection urlc = url.openConnection();
System.out.println("Created URLConnection");
System.out.println("About to create the BufferedReader");
BufferedReader bR = new BufferedReader(new
InputStreamReader(urlc.getInputStream()));
System.out.println("Created the BufferedReader");
System.out.println("About to create a StringBuilder");
StringBuilder sBuilder = new StringBuilder();
System.out.println("Created StringBuilder");
int byteRead;
System.out.println("About to enter while loop and build string");
while ((byteRead = bR.read()) != -1)
{
sBuilder.append((char) byteRead);
}
System.out.println("Built string");
bR.close();
System.out.println("Buffered reader is closed");
String text = sBuilder.toString();
System.out.println(text);
}
catch (IOException e)
{
//
}
そして、ここに私が得るログ(のいくつか)があります:
07-24 13:56:17.546: I/System.out(1554): About to create URL.
07-24 13:56:17.557: I/System.out(1554): Created URL
07-24 13:56:17.557: I/System.out(1554): About to create URLConnection
07-24 13:56:17.557: I/System.out(1554): Created URLConnection
07-24 13:56:17.557: I/System.out(1554): About to create the BufferedReader
07-24 13:56:17.576: D/AndroidRuntime(1554): Shutting down VM
07-24 13:56:17.576: W/dalvikvm(1554): threadid=1: thread exiting with uncaught exception
(group=0x40a13300)
07-24 13:56:17.606: E/AndroidRuntime(1554): FATAL EXCEPTION: main
07-24 13:56:17.606: E/AndroidRuntime(1554): java.lang.RuntimeException: Unable to start
activity ComponentInfo{com. ...
前もって感謝します。