Android Tutorial on reading / writing simple files?

by superjet91 » Thu, 12 Mar 2009 10:22:32 GMT

Sponsored Links
 Does anyone know of a tutorial that explains how to do basic file
reading / writing in Android? Its hard getting back to OO programming
from matlab/perl!

All I want to do, in two parts:
1. Read a file from the SD card, and store the values into variables.
2. Read a file from a website, and store the values into variables.

Thanks for ANY help! :)



Other Threads

1. Google Feedback fo Android


I have some doubts about this feature (Android Application Error
Reports), described here

I have a Nexus One from ADL 2010, with 2.1-update1 firmware. When a
Launcher2 crashes I can send a report about this bug. But how? It's a
OS feature or app feature? I downloaded a CrashApp from market (by
Jacek Surazski, author of above post on dev blog), and when this app
crashed I also can see a "Report" button. I wrote a small app that
crashes and there is no "Report" button, so I concluded that it's an
app feature. But how to enabled it?

I wrote to Jacek Surazski with those questions but he didn't respond.
Any ideas?


2. nullPointerException with custom ArrayAdapter

There are only two choices (off the top of my head) that could cause a 
nullPointerException. One is the convertView is null, and the other is 
that the is not part of the layout of the convertView, so you get the 
NullPointerException when you try to cast it to EditText.

Can you post your entire getView method?

hello Brad, thanks for your reply. Isn't the call to super.getView(...) suppose to do this ?? I already told the adapter which layout to use (see the constructor of my adpater on my first post), so it should know which one to inflate. Anyways I tried something similar to what you suggested : if (convertView == null) { convertView = LayoutInflater.from(getApplicationContext()).inflate(R.layout.step_list_item, null); } but I've got a similar nullPointerException when I call "findViewById" : EditText ed = (EditText) convertView.findViewById(; // return null ed.setText("test"); // will crash Again, it works fine when the list is shown for the first time but it crash when I use "adapter.notifyDataSetChanged()" ... So "" is found in my layout the first time but not the second time ??? This is getting confusing :(
You need something like this in the getView to create the view if it hasn't been created already.: if (convertView == null) { LayoutInflater inflater = Groups.this.getLayoutInflater(); convertView = inflater.inflate(R.layout.groupitem, null); }
I have written a custom ArrayAdapter for a ListActivity :
private class StepItemAdapter extends ArrayAdapter<Step> { public StepItemAdapter(Context context, List<Step> objects) { super(context, R.layout.step_list_item,, objects); }
@Override public View getView(final int pos, View convertView, ViewGroup parent) { View v = super.getView(pos, convertView, parent); // will crash here
// etc ... } }
On the "onCreate" method of the activity I tell the activity to use this adapter with a list of object I get from somewhere else ("t.getSteps()") :
adapter = new StepItemAdapter(this, t.getSteps()); this.setListAdapter(adapter);
Everything works fine and the activity is displayed. But if I add a new object to the list and tell the adapter to refresh the view I've got an error :
t.getSteps().add(3, new Step()); adapter.notifyDataSetChanged();
The "getView" method of my adapter is called, which is ok since the list view need to be updated, but I've got an exception on the call to "super.getView(pos, convertView, parent)".
The stack trace :
java.lang.NullPointerException at android.widget.ArrayAdapter.createViewFromResource( 355) at android.widget.ArrayAdapter.getView( at $StepItemAdapter.getView( at android.widget.HeaderViewListAdapter.getView( 220) at android.widget.AbsListView.obtainView( at android.widget.ListView.makeAndAddView( at android.widget.ListView.fillDown( at android.widget.ListView.fillSpecific( at android.widget.ListView.layoutChildren( at android.widget.AbsListView.onLayout( ...
Do you guy have any ideas of what is going on ??
-- Sincerely, Brad Gies ----------------------------------------------------------------------- Bistro Bot - Bistro Blurbhttp://www.bgies.comhttp://www.bistroblurb.com ----------------------------------------------------------------------- Never doubt that a small group of thoughtful, committed people can change the world. Indeed. It is the only thing that ever has - Margaret Mead
-- Sincerely, Brad Gies ----------------------------------------------------------------------- Bistro Bot - Bistro Blurb ----------------------------------------------------------------------- Never doubt that a small group of thoughtful, committed people can change the world. Indeed. It is the only thing that ever has - Margaret Mead --

3. nullPointerException with custom ArrayAdapter

4. Eclipse not recoginizing my attached Hero, Ubuntu 9.10

5. nullPointerException with custom ArrayAdapter

6. Eclipse not recoginizing my attached Hero, Ubuntu 9.10

7. nullPointerException with custom ArrayAdapter