Read your code properly, you will get the problem. Check what is the file name("stations") given in your ReadXML file? It should be with extension .xml.
Other than this, there is other way to store and read the files using openFileInput and openFileOutput of the activity context. I guess those are the best methods to access files. Thanks, Upendra On Thu, Feb 25, 2010 at 4:17 PM, kavitha <kavith...@gmail.com> wrote: > > private String DOWNFILE = "stations.xml"; > File stations; > > //////////////////////////////////code to store file > > stations = new File(context.getCacheDir(),DOWNFILE); > url=" > http://www.permeative.com/projects/TimeShiftRadio/AppData/IndiaRadioStations.xml > "; > try{ > connection = new URL(url).openConnection(); > connection.connect(); > InputStream stream = connection.getInputStream(); > if (stream == null) { > Log.e(TAG, "Unable to create InputStream for mediaUrl: > "+url); > } > FileOutputStream fos = new FileOutputStream(stations); > > byte buf[] = new byte[16 * 1024]; > do { > int numread = stream.read(buf); > if (numread <= 0) { > break; > } else { > fos.write(numread); > } > } while (true); > fos.close(); > > }catch(Exception e){ > System.out.println("CANNOT DOWNLOAD STATIONS"); > e.printStackTrace(); > } > > > /////////////////////////////////////code to parse xml > try{ > if(stations.exists() && stations.canRead()){ > ReadXML readXML=new ReadXML(); > readXML.readFile(context,stations); > } > > }catch(Exception e){ > Log.e(TAG, "unable to read from file " + e); > e.printStackTrace(); > } > > > /////////////////////////////////////////////////////ReadXML.java looks > like this > > public class ReadXML{ > private String DOWNFILE = "stations"; > > > > public void readFile (Context context,File file){ > try { > > DocumentBuilderFactory docBuilderFactory = > DocumentBuilderFactory.newInstance(); > DocumentBuilder docBuilder = > docBuilderFactory.newDocumentBuilder(); > // File temp = new File(context.getCacheDir(),DOWNFILE); > // file=temp; > // Document doc = docBuilder.parse (new File(file.getName())); > Document doc = docBuilder.parse (file); > > // normalize text representation********************getting > error here,,telling filenotfound > doc.getDocumentElement ().normalize (); > System.out.println ("Root element of the doc is " + > doc.getDocumentElement().getNodeName()); > > } > > } > > I am getting error in ReadXML.java file > doc.getDocumentElement ().normalize (); > > > > > > On Thu, Feb 25, 2010 at 4:11 PM, Upendra Chintala < > upendra.chint...@gmail.com> wrote: > >> Post you code here, that may help us to provide some solution to you. >> Without looking at the code it's hard to imagine where is that >> NullPointerException? >> >> >> On Thu, Feb 25, 2010 at 4:06 PM, kavitha <kavith...@gmail.com> wrote: >> >>> Actually I could write file to local cache using InputStreamReader. >>> >>> I am downloading bytes successfully and could write to a file,,, >>> >>> But again if i try to open file and read it,,It is throwing >>> NullPointerException for file. >>> >>> >>> On Thu, Feb 25, 2010 at 4:00 PM, Upendra Chintala < >>> upendra.chint...@gmail.com> wrote: >>> >>>> A simple search on google would have helped you. >>>> >>>> >>>> http://digiassn.blogspot.com/2008/10/java-simple-httpurlconnection-example.html >>>> >>>> Upendra >>>> >>>> >>>> On Thu, Feb 25, 2010 at 3:55 PM, kavitha <kavith...@gmail.com> wrote: >>>> >>>>> Any examples please >>>>> >>>>> >>>>> On Thu, Feb 25, 2010 at 3:53 PM, Upendra Chintala < >>>>> upendra.chint...@gmail.com> wrote: >>>>> >>>>>> You can use HttpURLConnection object to read the file as stream and >>>>>> then store it locally. >>>>>> >>>>>> Thanks, >>>>>> Upendra >>>>>> >>>>>> >>>>>> On Thu, Feb 25, 2010 at 3:49 PM, kavitha <kavith...@gmail.com> wrote: >>>>>> >>>>>>> first download and keep the file >>>>>>> >>>>>>> then parse it,,,, >>>>>>> >>>>>>> i need to download bcoz when the application launches second time,,i >>>>>>> need to use stored file without re-downloading >>>>>>> >>>>>>> >>>>>>> On Thu, Feb 25, 2010 at 3:47 PM, Sandeep Phansekar < >>>>>>> sandeep.phanse...@gmail.com> wrote: >>>>>>> >>>>>>>> want to just download ? or parse the file ? >>>>>>>> -- >>>>>>>> Regards >>>>>>>> Sandeep >>>>>>>> >>>>>>>> On Thu, Feb 25, 2010 at 3:39 PM, kavitha <kavith...@gmail.com>wrote: >>>>>>>> >>>>>>>>> Hi All, >>>>>>>>> >>>>>>>>> Please tell how to download an xml file from url connection in >>>>>>>>> android? >>>>>>>>> >>>>>>>>> Thanks >>>>>>>>> >>>>>>>>> Kavitha >>>>>>>>> >>>>>>>>> -- >>>>>>>>> You received this message because you are subscribed to the Google >>>>>>>>> Groups "Android Developers" group. >>>>>>>>> To post to this group, send email to >>>>>>>>> android-developers@googlegroups.com >>>>>>>>> To unsubscribe from this group, send email to >>>>>>>>> android-developers+unsubscr...@googlegroups.com<android-developers%2bunsubscr...@googlegroups.com> >>>>>>>>> For more options, visit this group at >>>>>>>>> http://groups.google.com/group/android-developers?hl=en >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> -- >>>>>>>> You received this message because you are subscribed to the Google >>>>>>>> Groups "Android Developers" group. >>>>>>>> To post to this group, send email to >>>>>>>> android-developers@googlegroups.com >>>>>>>> To unsubscribe from this group, send email to >>>>>>>> android-developers+unsubscr...@googlegroups.com<android-developers%2bunsubscr...@googlegroups.com> >>>>>>>> For more options, visit this group at >>>>>>>> http://groups.google.com/group/android-developers?hl=en >>>>>>> >>>>>>> >>>>>>> -- >>>>>>> You received this message because you are subscribed to the Google >>>>>>> Groups "Android Developers" group. >>>>>>> To post to this group, send email to >>>>>>> android-developers@googlegroups.com >>>>>>> To unsubscribe from this group, send email to >>>>>>> android-developers+unsubscr...@googlegroups.com<android-developers%2bunsubscr...@googlegroups.com> >>>>>>> For more options, visit this group at >>>>>>> http://groups.google.com/group/android-developers?hl=en >>>>>>> >>>>>> >>>>>> >>>>>> >>>>>> -- >>>>>> Regards, >>>>>> Upendra >>>>>> >>>>>> -- >>>>>> You received this message because you are subscribed to the Google >>>>>> Groups "Android Developers" group. >>>>>> To post to this group, send email to >>>>>> android-developers@googlegroups.com >>>>>> To unsubscribe from this group, send email to >>>>>> android-developers+unsubscr...@googlegroups.com<android-developers%2bunsubscr...@googlegroups.com> >>>>>> For more options, visit this group at >>>>>> http://groups.google.com/group/android-developers?hl=en >>>>>> >>>>> >>>>> -- >>>>> You received this message because you are subscribed to the Google >>>>> Groups "Android Developers" group. >>>>> To post to this group, send email to >>>>> android-developers@googlegroups.com >>>>> To unsubscribe from this group, send email to >>>>> android-developers+unsubscr...@googlegroups.com<android-developers%2bunsubscr...@googlegroups.com> >>>>> For more options, visit this group at >>>>> http://groups.google.com/group/android-developers?hl=en >>>>> >>>> >>>> >>>> >>>> -- >>>> Regards, >>>> Upendra >>>> >>>> -- >>>> You received this message because you are subscribed to the Google >>>> Groups "Android Developers" group. >>>> To post to this group, send email to >>>> android-developers@googlegroups.com >>>> To unsubscribe from this group, send email to >>>> android-developers+unsubscr...@googlegroups.com<android-developers%2bunsubscr...@googlegroups.com> >>>> For more options, visit this group at >>>> http://groups.google.com/group/android-developers?hl=en >>>> >>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "Android Developers" group. >>> To post to this group, send email to android-developers@googlegroups.com >>> To unsubscribe from this group, send email to >>> android-developers+unsubscr...@googlegroups.com<android-developers%2bunsubscr...@googlegroups.com> >>> For more options, visit this group at >>> http://groups.google.com/group/android-developers?hl=en >>> >> >> >> >> -- >> Regards, >> Upendra >> >> -- >> You received this message because you are subscribed to the Google >> Groups "Android Developers" group. >> To post to this group, send email to android-developers@googlegroups.com >> To unsubscribe from this group, send email to >> android-developers+unsubscr...@googlegroups.com<android-developers%2bunsubscr...@googlegroups.com> >> For more options, visit this group at >> http://groups.google.com/group/android-developers?hl=en >> > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to android-developers@googlegroups.com > To unsubscribe from this group, send email to > android-developers+unsubscr...@googlegroups.com<android-developers%2bunsubscr...@googlegroups.com> > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en > -- Regards, Upendra -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en