I'm using the code in this fashion: try{
URL myURL = new URL("http://www.indulec.ie/weather.txt"); URLConnection conn = myURL.openConnection(); conn.connect(); BufferedReader is = new BufferedReader(new InputStreamReader (conn.getInputStream(), "UTF-8")); FileOutputStream fOut = openFileOutput("news.txt", MODE_WORLD_READABLE); OutputStreamWriter osw = new OutputStreamWriter(fOut, "UTF-8"); String istr; while ((istr = is.readLine()) != null) osw.write(istr+"\n"); osw.close(); setContentView(R.layout.latestnews); String text = new String(istr); TextView tv = (TextView)findViewById(R.id.somenews); tv.setText(text); } catch ( IOException e ) { Log.d(TAG, "Can not connect to the target server!" ); try { throw new IOException(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } but I'm just getting an error saying the app has stopped unexpectedly. The whole setContentView() bit is wrong but i'm just not sure how to access the news.txt file once it has been saved in the devices data files. On Mar 22, 1:39 pm, Mark Murphy <mmur...@commonsware.com> wrote: > murphy wrote: > > Thanks for the explanation. I found the files there alright so the > > code is working which is great. Now I need to access the files in the > > device to display their contents in a TextView in a screen. I've been > > trying to do something like this: > > > String text = new String(istr); > > TextView tv = (TextView)findViewById(R.id.somenews); > > tv.setText(text); > > setContentView(R.layout.latestnews); > > > but I'm not really sure how to do it. > > setContentView() has to be called before findViewById(), assuming the > layout you define in setContentView() has the widgets you're trying to > access in findViewById(). > > -- > Mark Murphy (a Commons Guy)http://commonsware.com > _The Busy Coder's Guide to Android Development_ Version 2.0 Available! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---