0

Can you please tell me why does the SAX parser break on this line:

InputStream inputStream = new URL(url).openStream(); 

Previously I have constructed url like this:

private String url = "http://www.nasa.gov/rss/image_of_the_day.rss";

URL is current and functional so it is not due to it.

I am new to SAX so please forgive me for my ignorance.

Here is the error log from Eclipse:

11-30 20:27:24.892: E/AndroidRuntime(2388): FATAL EXCEPTION: main 11-30 20:27:24.892: E/AndroidRuntime(2388): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.headfirstlabs.nasadailyimage/com.headfirstlabs.nasadailyimage.NasaDailyImage}: java.lang.NullPointerException 11-30 20:27:24.892: E/AndroidRuntime(2388): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1955) 11-30 20:27:24.892: E/AndroidRuntime(2388): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980) 11-30 20:27:24.892: E/AndroidRuntime(2388): at android.app.ActivityThread.access$600(ActivityThread.java:122) 11-30 20:27:24.892: E/AndroidRuntime(2388): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146) 11-30 20:27:24.892: E/AndroidRuntime(2388): at android.os.Handler.dispatchMessage(Handler.java:99) 11-30 20:27:24.892: E/AndroidRuntime(2388): at android.os.Looper.loop(Looper.java:137) 11-30 20:27:24.892: E/AndroidRuntime(2388): at android.app.ActivityThread.main(ActivityThread.java:4340) 11-30 20:27:24.892: E/AndroidRuntime(2388): at java.lang.reflect.Method.invokeNative(Native Method) 11-30 20:27:24.892: E/AndroidRuntime(2388): at java.lang.reflect.Method.invoke(Method.java:511) 11-30 20:27:24.892: E/AndroidRuntime(2388): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) 11-30 20:27:24.892: E/AndroidRuntime(2388): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 11-30 20:27:24.892: E/AndroidRuntime(2388): at dalvik.system.NativeStart.main(Native Method) 11-30 20:27:24.892: E/AndroidRuntime(2388): Caused by: java.lang.NullPointerException 11-30 20:27:24.892: E/AndroidRuntime(2388): at com.headfirstlabs.nasadailyimage.IotdHandler.processFeed(IotdHandler.java:58) 11-30 20:27:24.892: E/AndroidRuntime(2388): at com.headfirstlabs.nasadailyimage.NasaDailyImage.onCreate(NasaDailyImage.java:18) 11-30 20:27:24.892: E/AndroidRuntime(2388): at android.app.Activity.performCreate(Activity.java:4465) 11-30 20:27:24.892: E/AndroidRuntime(2388): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049) 11-30 20:27:24.892: E/AndroidRuntime(2388): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919) 11-30 20:27:24.892: E/AndroidRuntime(2388): ... 11 more

TunAntun
  • 91
  • 10
  • 4
    The line of code you posted has nothing to do with SAX. Add the error stacktrace to your question. – Perception Nov 30 '12 at 11:59
  • make sure device is connected to internet... – ashish.n Nov 30 '12 at 13:16
  • Thank you all, I am installing source code from Android in order to catch an error as Eclipse gives me "Source code unavailable" error if I try to look at the exception. I will contact you again when done – TunAntun Nov 30 '12 at 18:10

2 Answers2

0

You need to catch the exception that is thrown when you attempt to open the stream, and print out (at least) the exception message. This should be sufficient to explain why the openStream() call isn't working.

(My guess would be either that your access to the site is blocked by a firewall, or you are actually attempting to connect to a different URL. It is also possible that you have somehow got the wrong code line ...)

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • Thank you all, I am installing source code from Android in order to catch an error as Eclipse gives me "Source code unavailable" error if I try to look at the exception. I will contact you again when done. – TunAntun Nov 30 '12 at 18:10
  • OK; I found a solution. Look at this: http://oreilly.com/catalog/errataunconfirmed.csp?isbn=0636920012825 – TunAntun Dec 01 '12 at 00:24
0

I found out there is an error page about this book. (Very big one) On page 105 it says that the parse method is missing a parameter.

You can have a look here:

http://oreilly.com/catalog/errataunconfirmed.csp?isbn=0636920012825

TunAntun
  • 91
  • 10