Can you give us a little more info, like where the NullPointerException happens in the code?
---------------------------------------------------------------------- There are only 10 types of people in the world... Those who know binary and those who don't. ---------------------------------------------------------------------- On Mon, Feb 1, 2010 at 3:09 PM, Sam B <[email protected]> wrote: > Hi guys im trying to put a button on each row of a list but i get null > pointer exception, i'll show the java files below. The list view is in > a seperate xml file to the button because button is inside a relative > layout. Can anyone help?. > > This class gets data from a database and puts it in array and displays > in a list view which works fine until i try to put a button in each > row. > Java: > > package project.Maps; > public class SatMain extends Activity { > /** Called when the activity is first created. */ > ArrayList<String> results = new ArrayList<String>(); > @Override > public void onCreate(Bundle savedInstanceState) > { > super.onCreate(savedInstanceState); > setContentView(R.layout.main); > dbAdapter db = new dbAdapter(this); > > ; > > > > //---get all titles--- > db.open(); > db.InsertData(); > > Cursor c = db.getSat1(); > > if (c.moveToFirst()) > { > do { > String pub = c.getString(c.getColumnIndex > (db.KEY_Artist)); > String pub1 = c.getString(c.getColumnIndex > (db.KEY_Time)); > > > > results.add(pub + pub1 ); > } while (c.moveToNext()); > } > db.close(); > > ListView listProducts; > List<String> results = new ArrayList<String>(); > Context cont = null; > customArray ca = new customArray(cont, R.layout.button, > results); > listProducts = (ListView)findViewById(R.id.list123); > listProducts.setAdapter(ca); > ca.notifyDataSetChanged(); > }} > > > > Code for my custom adapter. > > Java: > > package project.Maps; > import java.util.List; > public class customArray extends ArrayAdapter<String> { > int resource; > > public customArray(Context cont, int _resource, List<String> > results) { > super (cont, _resource, results); > resource = _resource; > } > > @Override > public View getView(int position, View convertView, ViewGroup > parent) { > RelativeLayout rl; > > // String prod = getItem(position); > if (convertView == null) { > rl = new RelativeLayout(getContext()); > LayoutInflater vi = (LayoutInflater)getContext > ().getSystemService(Context.LAYOUT_INFLATER_SERVICE); > vi.inflate(resource, rl, true); > } else { > rl = (RelativeLayout)convertView; > } > > > return rl; > } > } > > -- > You received this message because you are subscribed to the Google > Groups "Android Beginners" group. > > NEW! Try asking and tagging your question on Stack Overflow at > http://stackoverflow.com/questions/tagged/android > > To unsubscribe from this group, send email to > [email protected]<android-beginners%[email protected]> > For more options, visit this group at > http://groups.google.com/group/android-beginners?hl=en > -- You received this message because you are subscribed to the Google Groups "Android Beginners" group. NEW! Try asking and tagging your question on Stack Overflow at http://stackoverflow.com/questions/tagged/android To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en

