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 <
[email protected]> 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 <[email protected]> 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 <
>> [email protected]> 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 <[email protected]> wrote:
>>>
>>>> Any examples please
>>>>
>>>>
>>>> On Thu, Feb 25, 2010 at 3:53 PM, Upendra Chintala <
>>>> [email protected]> 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 <[email protected]> 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 <
>>>>>> [email protected]> wrote:
>>>>>>
>>>>>>> want to just download ? or parse the file ?
>>>>>>> --
>>>>>>> Regards
>>>>>>> Sandeep
>>>>>>>
>>>>>>> On Thu, Feb 25, 2010 at 3:39 PM, kavitha <[email protected]>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
>>>>>>>> [email protected]
>>>>>>>> To unsubscribe from this group, send email to
>>>>>>>> [email protected]<android-developers%[email protected]>
>>>>>>>> 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
>>>>>>> [email protected]
>>>>>>> To unsubscribe from this group, send email to
>>>>>>> [email protected]<android-developers%[email protected]>
>>>>>>> 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
>>>>>> [email protected]
>>>>>> To unsubscribe from this group, send email to
>>>>>> [email protected]<android-developers%[email protected]>
>>>>>> 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
>>>>> [email protected]
>>>>> To unsubscribe from this group, send email to
>>>>> [email protected]<android-developers%[email protected]>
>>>>> 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
>>>> [email protected]
>>>> To unsubscribe from this group, send email to
>>>> [email protected]<android-developers%[email protected]>
>>>> 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 [email protected]
>>> To unsubscribe from this group, send email to
>>> [email protected]<android-developers%[email protected]>
>>> 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 [email protected]
>> To unsubscribe from this group, send email to
>> [email protected]<android-developers%[email protected]>
>> 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 [email protected]
> To unsubscribe from this group, send email to
> [email protected]<android-developers%[email protected]>
> 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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to