- Forum-Beiträge: 30
23.08.2013, 12:38:12 via Website
23.08.2013 12:38:12 via Website
ich benötige den Seiteninhalt einer Bestimmten Url als String, deswegen wollte ich folgendes Snippet verwenden:
http://cdrussell.blogspot.de/2011/12/android-get-body-of-http-response-as.html
Ich habe die Internet-Permission in der Manifestdatei hinzugefügt, dennoch stürzt die App ab.
Hier das Logcat-Protokoll:
08-23 10:32:02.576 1153-1153/com.fotoboxxv1.fotoboxxat I/Choreographer: Skipped 67 frames! The application may be doing too much work on its main thread.
08-23 10:32:03.066 275-291/system_process I/ActivityManager: Displayed com.fotoboxxv1.fotoboxxat/.RegistrierenActivity: +2s446ms
08-23 10:32:06.005 362-362/com.android.inputmethod.latin I/Choreographer: Skipped 80 frames! The application may be doing too much work on its main thread.
08-23 10:32:06.105 37-88/? E/SurfaceFlinger: ro.sf.lcd_density must be defined as a build property
08-23 10:32:10.716 1153-1153/com.fotoboxxv1.fotoboxxat E/fotoboxx: Versuche zu Registieren
08-23 10:32:10.726 1153-1153/com.fotoboxxv1.fotoboxxat D/fotoboxx: Versuche aufzurufen: http://www.google.de?q=test
08-23 10:32:10.896 1153-1153/com.fotoboxxv1.fotoboxxat D/AndroidRuntime: Shutting down VM
08-23 10:32:10.896 1153-1153/com.fotoboxxv1.fotoboxxat W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x40a71930)
08-23 10:32:10.976 1153-1153/com.fotoboxxv1.fotoboxxat E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.IllegalStateException: Could not execute method of the activity
at android.view.View$1.onClick(View.java:3599)
at android.view.View.performClick(View.java:4204)
at android.view.View$PerformClick.run(View.java:17355)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5041)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at android.view.View$1.onClick(View.java:3594)
... 11 more
Caused by: android.os.NetworkOnMainThreadException
at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1117)
at java.net.InetAddress.lookupHostByName(InetAddress.java:385)
at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
at java.net.InetAddress.getAllByName(InetAddress.java:214)
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137)
at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
at com.fotoboxxv1.fotoboxxat.RegistrierenActivity.onButtonRegiestrieren(RegistrierenActivity.java:64)
... 14 more
08-23 10:32:11.056 275-275/system_process W/ActivityManager: Force finishing activity com.fotoboxxv1.fotoboxxat/.RegistrierenActivity
08-23 10:32:11.066 275-275/system_process W/WindowManager: Failure taking screenshot for (246x410) to layer 21020
08-23 10:32:11.266 275-292/system_process I/Choreographer: Skipped 35 frames! The application may be doing too much work on its main thread.
08-23 10:32:11.286 37-37/? E/SurfaceFlinger: ro.sf.lcd_density must be defined as a build property
08-23 10:32:11.640 275-289/system_process W/ActivityManager: Activity pause timeout for ActivityRecord{40f68548 u0 com.fotoboxxv1.fotoboxxat/.RegistrierenActivity}
08-23 10:32:13.607 1153-1153/com.fotoboxxv1.fotoboxxat I/Process: Sending signal. PID: 1153 SIG: 9
Und so sieht meine Methode bis jetzt aus:
2
3 Log.d("fotoboxx", "Versuche aufzurufen: " + aufzurufendeUrl);
4
5 DefaultHttpClient http = new DefaultHttpClient();
6 HttpGet httpMethod = new HttpGet();
7 try {
8 httpMethod.setURI(new URI(aufzurufendeUrl));
9 } catch (URISyntaxException e) {
10 e.printStackTrace();
11 Log.e("fotoboxx","UriSyntaxException");
12 }
13 HttpResponse response = null;
14 try {
15 response = http.execute(httpMethod);
16 } catch (IOException e) {
17 e.printStackTrace();
18 Log.e("fotoboxx","IOExeption in http.execute()");
19 }
20 int responseCode = response.getStatusLine().getStatusCode();
21 switch(responseCode)
22 {
23 case 200:
24 HttpEntity entity = response.getEntity();
25 if(entity != null)
26 {
27 try {
28 String responseBody = EntityUtils.toString(entity);
29
30 AlertDialog ad = new AlertDialog.Builder(this).create();
31 ad.setCancelable(false); // This blocks the 'BACK' button
32 ad.setMessage(responseBody);
33 ad.setButton("OK", new DialogInterface.OnClickListener() {
34 @Override
35 public void onClick(DialogInterface dialog, int which) {
36 dialog.dismiss();
37 }
38 });
39 ad.show();
40 } catch (IOException e) {
41 e.printStackTrace();
42 Log.e("fotoboxx","IOExeption in responseCode");
43 }
44
45 }
46 break;
47 }
Hat jemand eventuell eine Idee?
Danke schon mal für eure Hilfe.
Gruß,
NeuHier
Empfohlener redaktioneller Inhalt
Mit Deiner Zustimmung wird hier ein externer Inhalt geladen.
Mit Klick auf den oben stehenden Button erklärst Du Dich damit einverstanden, dass Dir externe Inhalte angezeigt werden dürfen. Dabei können personenbezogene Daten an Drittanbieter übermittelt werden. Mehr Infos dazu findest Du in unserer Datenschutzerklärung.