Hey,
ich versuche gerade den Quelltext einer HTML Datei aus dem Internet auszulesen.
Mein Versuch:
Code
URL url = null;
try {
url = new URL("URL");
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
BufferedReader in;
try {
in = new BufferedReader(
new InputStreamReader(
url.openStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
text = text + inputLine;
in.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Alles anzeigen
Mein Fehler:
Code
12-26 00:42:25.485: E/Trace(1147): error opening trace file: No such file or directory (2)
12-26 00:42:26.155: D/AndroidRuntime(1147): Shutting down VM
12-26 00:42:26.155: W/dalvikvm(1147): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
12-26 00:42:26.196: E/AndroidRuntime(1147): FATAL EXCEPTION: main
12-26 00:42:26.196: E/AndroidRuntime(1147): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.homeconnector/com.example.homeconnector.MainActivity}: android.os.NetworkOnMainThreadException
12-26 00:42:26.196: E/AndroidRuntime(1147): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
12-26 00:42:26.196: E/AndroidRuntime(1147): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
12-26 00:42:26.196: E/AndroidRuntime(1147): at android.app.ActivityThread.access$600(ActivityThread.java:130)
12-26 00:42:26.196: E/AndroidRuntime(1147): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
12-26 00:42:26.196: E/AndroidRuntime(1147): at android.os.Handler.dispatchMessage(Handler.java:99)
12-26 00:42:26.196: E/AndroidRuntime(1147): at android.os.Looper.loop(Looper.java:137)
12-26 00:42:26.196: E/AndroidRuntime(1147): at android.app.ActivityThread.main(ActivityThread.java:4745)
12-26 00:42:26.196: E/AndroidRuntime(1147): at java.lang.reflect.Method.invokeNative(Native Method)
12-26 00:42:26.196: E/AndroidRuntime(1147): at java.lang.reflect.Method.invoke(Method.java:511)
12-26 00:42:26.196: E/AndroidRuntime(1147): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
12-26 00:42:26.196: E/AndroidRuntime(1147): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
12-26 00:42:26.196: E/AndroidRuntime(1147): at dalvik.system.NativeStart.main(Native Method)
12-26 00:42:26.196: E/AndroidRuntime(1147): Caused by: android.os.NetworkOnMainThreadException
12-26 00:42:26.196: E/AndroidRuntime(1147): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1117)
12-26 00:42:26.196: E/AndroidRuntime(1147): at java.net.InetAddress.lookupHostByName(InetAddress.java:385)
12-26 00:42:26.196: E/AndroidRuntime(1147): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
12-26 00:42:26.196: E/AndroidRuntime(1147): at java.net.InetAddress.getAllByName(InetAddress.java:214)
12-26 00:42:26.196: E/AndroidRuntime(1147): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:70)
12-26 00:42:26.196: E/AndroidRuntime(1147): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)
12-26 00:42:26.196: E/AndroidRuntime(1147): at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:341)
12-26 00:42:26.196: E/AndroidRuntime(1147): at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:87)
12-26 00:42:26.196: E/AndroidRuntime(1147): at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
12-26 00:42:26.196: E/AndroidRuntime(1147): at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:315)
12-26 00:42:26.196: E/AndroidRuntime(1147): at libcore.net.http.HttpEngine.connect(HttpEngine.java:310)
12-26 00:42:26.196: E/AndroidRuntime(1147): at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:289)
12-26 00:42:26.196: E/AndroidRuntime(1147): at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:239)
12-26 00:42:26.196: E/AndroidRuntime(1147): at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:273)
12-26 00:42:26.196: E/AndroidRuntime(1147): at libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:168)
12-26 00:42:26.196: E/AndroidRuntime(1147): at java.net.URL.openStream(URL.java:462)
12-26 00:42:26.196: E/AndroidRuntime(1147): at com.example.homeconnector.MainActivity.onCreate(MainActivity.java:42)
12-26 00:42:26.196: E/AndroidRuntime(1147): at android.app.Activity.performCreate(Activity.java:5008)
12-26 00:42:26.196: E/AndroidRuntime(1147): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
12-26 00:42:26.196: E/AndroidRuntime(1147): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
12-26 00:42:26.196: E/AndroidRuntime(1147): ... 11 more
12-26 00:47:26.394: I/Process(1147): Sending signal. PID: 1147 SIG: 9
Alles anzeigen
Könnt ihr mir helfen das zum laufen zu bekommen?