I'm new to this, so bear with me if I make any noob mistakes. I'm trying to write a database and return a random entry from the database. The program should launch a Randomize activity that will update a text view when the randomize button is pressed. \ public void randomize(View v) { view.setText(randRecipe());}
public String randRecipe()
{
Random rand= new Random();
int r= rand.nextInt(base.size());
Recipe rec= base.get(r);
return rec.toString();
}
This is the code that I put in my Randomize activity and although it worked once for some reason, my program crashes every time I try to randomize again. base is the List that I retrieved that contains all the recipe entry names. I figured since I used it to populate my ListView, I could use it again to access it in the randomize.
Should I try to get the value from the database directly? If so, how would I do that and can someone provide an example?