Simple Connect code doesnt work =(

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

Simple Connect code doesnt work =(

Postby chaoz1336 » Tue Aug 11, 2009 10:36 am

Hey guys, please help me, its very very urgent =/

here's the code:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package com.cortado.android;
  2.  
  3.  
  4.  
  5. import java.io.IOException;
  6.  
  7. import java.net.HttpURLConnection;
  8.  
  9. import java.net.MalformedURLException;
  10.  
  11. import java.net.URL;
  12.  
  13. import java.util.logging.Level;
  14.  
  15. import java.util.logging.Logger;
  16.  
  17.  
  18.  
  19. import android.app.ListActivity;
  20.  
  21. import android.os.Bundle;
  22.  
  23.  
  24.  
  25. public class Test extends Activity
  26.  
  27. {
  28.  
  29.     @Override
  30.  
  31.     public void onCreate(Bundle icicle)
  32.  
  33.     {
  34.  
  35.         super.onCreate(icicle);
  36.  
  37.        
  38.  
  39.         try
  40.  
  41.         {
  42.  
  43.             HttpURLConnection oConn = (HttpURLConnection) new URL("http://www.google.com").openConnection();
  44.  
  45.             Logger.getAnonymousLogger().log(Level.INFO, "=====> "+ oConn.getResponseCode());
  46.  
  47.         }
  48.  
  49.         catch (MalformedURLException e)
  50.  
  51.         {
  52.  
  53.             Logger.getAnonymousLogger().log(Level.INFO, "e - "+ e.toString());
  54.  
  55.             e.printStackTrace();
  56.  
  57.         }
  58.  
  59.         catch (IOException e)
  60.  
  61.         {
  62.  
  63.             Logger.getAnonymousLogger().log(Level.INFO, "e - "+ e.toString());
  64.  
  65.             e.printStackTrace();
  66.  
  67.         }
  68.  
  69.        
  70.  
  71.         Logger.getAnonymousLogger().log(Level.INFO, "~~~~~~~~~~ end ~~~~~~~~~~");
  72.  
  73.     }
  74.  
  75. }
Parsed in 0.035 seconds, using GeSHi 1.0.8.4



everything works fine, until I use oConn.getResponseCode();
permissions are also set in the manifest =/


stacktrace:

08-11 09:30:26.621: INFO/InetAddress(815): Unknown host www.google.com, throwing UnknownHostException
08-11 09:30:26.630: INFO/null(815): e - java.net.SocketException: Permission denied (maybe missing INTERNET permission)
08-11 09:30:26.630: WARN/System.err(815): java.net.SocketException: Permission denied (maybe missing INTERNET permission)
08-11 09:30:26.640: WARN/System.err(815): at org.apache.harmony.luni.platform.OSNetworkSystem.createSocketImpl(Native Method)
08-11 09:30:26.640: WARN/System.err(815): at org.apache.harmony.luni.platform.OSNetworkSystem.createSocket(OSNetworkSystem.java:85)
08-11 09:30:26.650: WARN/System.err(815): at org.apache.harmony.luni.net.PlainSocketImpl2.create(PlainSocketImpl2.java:59)
08-11 09:30:26.650: WARN/System.err(815): at java.net.Socket.checkClosedAndCreate(Socket.java:829)
08-11 09:30:26.660: WARN/System.err(815): at java.net.Socket.connect(Socket.java:984)
08-11 09:30:26.660: WARN/System.err(815): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:67)
08-11 09:30:26.660: WARN/System.err(815): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionManager$ConnectionPool.getHttpConnection(HttpConnectionManager.java:151)
08-11 09:30:26.660: WARN/System.err(815): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionManager.getConnection(HttpConnectionManager.java:73)
08-11 09:30:26.660: WARN/System.err(815): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.getHTTPConnection(HttpURLConnection.java:826)
08-11 09:30:26.660: WARN/System.err(815): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:812)
08-11 09:30:26.660: WARN/System.err(815): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.getResponseCode(HttpURLConnection.java:1275)
08-11 09:30:26.669: WARN/System.err(815): at java.net.HttpURLConnection.getResponseMessage(HttpURLConnection.java:487)
08-11 09:30:26.669: WARN/System.err(815): at com.cortado.android.Test.onCreate(Test.java:25)
08-11 09:30:26.669: WARN/System.err(815): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
08-11 09:30:26.669: WARN/System.err(815): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2231)
08-11 09:30:26.679: WARN/System.err(815): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2284)
08-11 09:30:26.679: WARN/System.err(815): at android.app.ActivityThread.access$1800(ActivityThread.java:112)
08-11 09:30:26.679: WARN/System.err(815): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1692)
08-11 09:30:26.689: WARN/System.err(815): at android.os.Handler.dispatchMessage(Handler.java:99)
08-11 09:30:26.689: WARN/System.err(815): at android.os.Looper.loop(Looper.java:123)
08-11 09:30:26.689: WARN/System.err(815): at android.app.ActivityThread.main(ActivityThread.java:3948)
08-11 09:30:26.689: WARN/System.err(815): at java.lang.reflect.Method.invokeNative(Native Method)
08-11 09:30:26.689: WARN/System.err(815): at java.lang.reflect.Method.invoke(Method.java:521)
08-11 09:30:26.689: WARN/System.err(815): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782)
08-11 09:30:26.689: WARN/System.err(815): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
08-11 09:30:26.689: WARN/System.err(815): at dalvik.system.NativeStart.main(Native Method)
08-11 09:30:26.689: INFO/null(815): ~~~~~~~~~~ end ~~~~~~~~~~
chaoz1336
Experienced Developer
Experienced Developer
 
Posts: 90
Joined: Wed Dec 10, 2008 5:19 pm

Top

Postby chaoz1336 » Tue Aug 11, 2009 11:07 am

little update...

I found out, that I can connect to every port80 server, but nothing else (like port 81... )
,...is there any special trick or something?
chaoz1336
Experienced Developer
Experienced Developer
 
Posts: 90
Joined: Wed Dec 10, 2008 5:19 pm

Postby chaoz1336 » Tue Aug 11, 2009 3:28 pm

ok i solved the prob, it was non-android, furthermore it was about the f***** windows dns settings -.-"
chaoz1336
Experienced Developer
Experienced Developer
 
Posts: 90
Joined: Wed Dec 10, 2008 5:19 pm

Top

Return to Networking & Database Problems

Who is online

Users browsing this forum: No registered users and 8 guests