ANDROID

meryembaha - 7 mai 2013 à 21:49
Twinuts Messages postés 5375 Date d'inscription dimanche 4 mai 2003 Statut Modérateur Dernière intervention 14 juin 2023 - 12 mai 2013 à 14:36
BONJOUR TOUT LE MONDE;
j'aimerai bien savoir où est l'erreur dans mon code.

voilà la fonction qui cherche un produit:

public Produit find(int id){
Produit p=null;
Cursor c=db.query("produit", new String[] {"description","prix","quantite"}, "idProduit="+id, null, null, null, "prix");
c.moveToFirst();
if(c.isAfterLast())
{
p.setIdProduit(c.getInt(1));
p.setDescription(c.getString(2));
p.setPrix(c.getInt(3));
p.setQuantite(c.getInt(4));
}
c.moveToNext();
return p;

}

voilà le code du boton rechercher:

if(v.getId()==R.id.button2)
{
t.open();
t1.setText("description");
t2.setText("prix");
t3.setText("quantite");
Produit p=t.find(Integer.parseInt(rech.getText().toString()));

t3.setText(p.getDescription().toString());
t4.setText(p.getPrix());
t5.setText(p.getQuantite());

t.close();
}

lorsque je clique sur le bouton rechercher aprés donner un idProduit il me génère une erreur

1 réponse

Twinuts Messages postés 5375 Date d'inscription dimanche 4 mai 2003 Statut Modérateur Dernière intervention 14 juin 2023 111
12 mai 2013 à 14:36
Salut,

Dans la fonction 'find' tu initialises 'p' à null mais tu ne fais jamais de new...


-----

"On n'est pas au resto : ici on ne fait pas dans les plats tout cuits ..."

OoWORAoO
0
Rejoignez-nous