Link to home
Start Free TrialLog in
Avatar of HLRosenberger
HLRosenbergerFlag for United States of America

asked on

http connection from java

I have this simple code.  It's causes an exception.  I just want to make an HTTP connection to a WEB site:


URL myurl = new URL("http://www.nasa.gov/rss/image_of_the_day.rss");
HttpURLConnection connection = (HttpURLConnection) myurl.openConnection();
int responseCode = connection.getResponseCode();
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

I have this simple code.  It's causes an exception.
http://technojeeves.com/joomla/index.php/free/118-errors
Avatar of HLRosenberger

ASKER

11-11 14:03:06.826: E/AndroidRuntime(2671): FATAL EXCEPTION: main
11-11 14:03:06.826: E/AndroidRuntime(2671): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.networkapp/com.example.networkapp.MainActivity}: java.lang.NullPointerException
11-11 14:03:06.826: E/AndroidRuntime(2671):       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
11-11 14:03:06.826: E/AndroidRuntime(2671):       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
11-11 14:03:06.826: E/AndroidRuntime(2671):       at android.app.ActivityThread.access$600(ActivityThread.java:130)
11-11 14:03:06.826: E/AndroidRuntime(2671):       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
11-11 14:03:06.826: E/AndroidRuntime(2671):       at android.os.Handler.dispatchMessage(Handler.java:99)
11-11 14:03:06.826: E/AndroidRuntime(2671):       at android.os.Looper.loop(Looper.java:137)
11-11 14:03:06.826: E/AndroidRuntime(2671):       at android.app.ActivityThread.main(ActivityThread.java:4745)
11-11 14:03:06.826: E/AndroidRuntime(2671):       at java.lang.reflect.Method.invokeNative(Native Method)
11-11 14:03:06.826: E/AndroidRuntime(2671):       at java.lang.reflect.Method.invoke(Method.java:511)
11-11 14:03:06.826: E/AndroidRuntime(2671):       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
11-11 14:03:06.826: E/AndroidRuntime(2671):       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-11 14:03:06.826: E/AndroidRuntime(2671):       at dalvik.system.NativeStart.main(Native Method)
11-11 14:03:06.826: E/AndroidRuntime(2671): Caused by: java.lang.NullPointerException
11-11 14:03:06.826: E/AndroidRuntime(2671):       at android.widget.Toast.<init>(Toast.java:92)
11-11 14:03:06.826: E/AndroidRuntime(2671):       at android.widget.Toast.makeText(Toast.java:238)
11-11 14:03:06.826: E/AndroidRuntime(2671):       at com.example.networkapp.MainActivity.onCreate(MainActivity.java:86)
11-11 14:03:06.826: E/AndroidRuntime(2671):       at android.app.Activity.performCreate(Activity.java:5008)
11-11 14:03:06.826: E/AndroidRuntime(2671):       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
11-11 14:03:06.826: E/AndroidRuntime(2671):       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
11-11 14:03:06.826: E/AndroidRuntime(2671):       ... 11 more
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ok.  thanks.
fwiw, in J2SE, it gives a 200
Correct, I should get a 200 HTTP status code.
This must be an Android thjing.   If I create just a Java app, all is OK.
Thakns
:)