UnknownHostException calling url.openStream()

Problems with WiFi, SQLite ,Bluetooth, WiMax, Proxies, etc...

UnknownHostException calling url.openStream()

Postby Mathias » Fri Jan 30, 2009 11:25 am

Hi,

I'm trying to read a file via http. (http://www-lehre.inf.uos.de/
~mmenning/balingen.ts). I wrote a Connector Class:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. package gip.android.ogl;
  3.  
  4.  
  5.  
  6. import java.io.IOException;
  7.  
  8. import java.io.InputStream;
  9.  
  10. import java.net.URL;
  11.  
  12.  
  13.  
  14. import android.util.Log;
  15.  
  16.  
  17.  
  18. public class DataConnectorTS {
  19.  
  20.  
  21.  
  22.         private final String DEBUG_TAG = "DataConnectorTS";
  23.  
  24.  
  25.  
  26.         public DataConnectorTS() {}
  27.  
  28.  
  29.  
  30.         public void requestTS(String address) {
  31.  
  32.                 try {
  33.  
  34.  
  35.  
  36.                         URL url = new URL(address);
  37.  
  38.                         Log.d(DEBUG_TAG, "url: " + url);
  39.  
  40.                         Log.d(DEBUG_TAG,"host: "+url.getHost());
  41.  
  42.                         readData(url.openStream());
  43.  
  44.  
  45.  
  46.                 } catch (IOException e) {
  47.  
  48.                         Log.e(DEBUG_TAG, "JML request IOError", e);
  49.  
  50.                 }
  51.  
  52.         }
  53.  
  54.  
  55.  
  56.         private void readData(InputStream in){
  57.  
  58.  
  59.  
  60.         }
  61.  
  62.  
  63.  
  64. }
  65.  
  66.  
Parsed in 0.034 seconds, using GeSHi 1.0.8.4



But by trying to connect in the ActivityClass
DataConnectorTS dcts= new DataConnectorTS();
dcts.requestTS("http://www-lehre.inf.uos.de/~mmenning/
balingen.jml");

I will only get the following ExceptionTrace:

01-27 17:00:18.605: ERROR/DataConnectorTS(182): JML request IOError
01-27 17:00:18.605: ERROR/DataConnectorTS(182):
java.net.UnknownHostException: Host is unresolved: www-
lehre.inf.uos.de:80
01-27 17:00:18.605: ERROR/DataConnectorTS(182): at
java.net.Socket.connect(Socket.java:928)
01-27 17:00:18.605: ERROR/DataConnectorTS(182): at
org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>
(HttpConnection.java:61)
01-27 17:00:18.605: ERROR/DataConnectorTS(182): at
org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionManager
$ConnectionPool.getHttpConnection(HttpConnectionManager.java:145)
01-27 17:00:18.605: ERROR/DataConnectorTS(182): at
org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionManager.getConnection
(HttpConnectionManager.java:67)
01-27 17:00:18.605: ERROR/DataConnectorTS(182): at
org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.getHTTPConnection
(HttpURLConnection.java:800)
01-27 17:00:18.605: ERROR/DataConnectorTS(182): at
org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.connect
(HttpURLConnection.java:786)
01-27 17:00:18.605: ERROR/DataConnectorTS(182): at
org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.getInputStream
(HttpURLConnection.java:1030)
01-27 17:00:18.605: ERROR/DataConnectorTS(182): at
java.net.URL.openStream(URL.java:664)
01-27 17:00:18.605: ERROR/DataConnectorTS(182): at
gip.android.ogl.DataConnectorTS.requestTS(DataConnectorTS.java:35)
01-27 17:00:18.605: ERROR/DataConnectorTS(182): at
gip.android.ogl.FirstOGLApp.onCreate(FirstOGLApp.java:14)
01-27 17:00:18.605: ERROR/DataConnectorTS(182): at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:
1122)
01-27 17:00:18.605: ERROR/DataConnectorTS(182): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
2103)
01-27 17:00:18.605: ERROR/DataConnectorTS(182): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:
2156)
01-27 17:00:18.605: ERROR/DataConnectorTS(182): at
android.app.ActivityThread.access$1800(ActivityThread.java:112)
01-27 17:00:18.605: ERROR/DataConnectorTS(182): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1580)
01-27 17:00:18.605: ERROR/DataConnectorTS(182): at
android.os.Handler.dispatchMessage(Handler.java:88)
01-27 17:00:18.605: ERROR/DataConnectorTS(182): at
android.os.Looper.loop(Looper.java:123)
01-27 17:00:18.605: ERROR/DataConnectorTS(182): at
android.app.ActivityThread.main(ActivityThread.java:3742)
01-27 17:00:18.605: ERROR/DataConnectorTS(182): at
java.lang.reflect.Method.invokeNative(Native Method)
01-27 17:00:18.605: ERROR/DataConnectorTS(182): at
java.lang.reflect.Method.invoke(Method.java:515)
01-27 17:00:18.605: ERROR/DataConnectorTS(182): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run
(ZygoteInit.java:739)
01-27 17:00:18.605: ERROR/DataConnectorTS(182): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:497)
01-27 17:00:18.605: ERROR/DataConnectorTS(182): at
dalvik.system.NativeStart.main(Native Method)

I already added the uses-permission INTERNET Tag to the manifest.xml
(above the application tag).

I can create the URL Instance but not call openStream().
I also tryed to get the Stream via a HTMLConnection and so on, nothing worked and without Android, this class works as expected....
Any Idea what the problem could be?

Thanks for any help

Mathias
Mathias
Freshman
Freshman
 
Posts: 3
Joined: Wed Jan 28, 2009 10:48 am

Top

Solved

Postby Mathias » Tue Feb 03, 2009 4:46 pm

The problem is www-lehre.... I just had to use the Host IP!!
One week lost.....
Mathias
Freshman
Freshman
 
Posts: 3
Joined: Wed Jan 28, 2009 10:48 am

Top

Return to Networking & Database Problems

Who is online

Users browsing this forum: No registered users and 3 guests