Problème lors d'un passage d'une activité à une autre
Bonjour,
Quand je clique sur l'Item de ma ListView, mon application plante et j'ai cette erreur:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| 06-08 16:56:18.933: E/AndroidRuntime(699): FATAL EXCEPTION: main
06-08 16:56:18.933: E/AndroidRuntime(699): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.cartedefidelite/com.example.cartedefidelite.FideliteActivity}: java.lang.NullPointerException
06-08 16:56:18.933: E/AndroidRuntime(699): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1955)
06-08 16:56:18.933: E/AndroidRuntime(699): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
06-08 16:56:18.933: E/AndroidRuntime(699): at android.app.ActivityThread.access$600(ActivityThread.java:122)
06-08 16:56:18.933: E/AndroidRuntime(699): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
06-08 16:56:18.933: E/AndroidRuntime(699): at android.os.Handler.dispatchMessage(Handler.java:99)
06-08 16:56:18.933: E/AndroidRuntime(699): at android.os.Looper.loop(Looper.java:137)
06-08 16:56:18.933: E/AndroidRuntime(699): at android.app.ActivityThread.main(ActivityThread.java:4340)
06-08 16:56:18.933: E/AndroidRuntime(699): at java.lang.reflect.Method.invokeNative(Native Method)
06-08 16:56:18.933: E/AndroidRuntime(699): at java.lang.reflect.Method.invoke(Method.java:511)
06-08 16:56:18.933: E/AndroidRuntime(699): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
06-08 16:56:18.933: E/AndroidRuntime(699): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
06-08 16:56:18.933: E/AndroidRuntime(699): at dalvik.system.NativeStart.main(Native Method)
06-08 16:56:18.933: E/AndroidRuntime(699): Caused by: java.lang.NullPointerException
06-08 16:56:18.933: E/AndroidRuntime(699): at com.example.cartedefidelite.AffichageClientActivity.onCreate(AffichageClientActivity.java:29)
06-08 16:56:18.933: E/AndroidRuntime(699): at com.example.cartedefidelite.FideliteActivity.onCreate(FideliteActivity.java:7)
06-08 16:56:18.933: E/AndroidRuntime(699): at android.app.Activity.performCreate(Activity.java:4465)
06-08 16:56:18.933: E/AndroidRuntime(699): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
06-08 16:56:18.933: E/AndroidRuntime(699): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)
06-08 16:56:18.933: E/AndroidRuntime(699): ... 11 more |
L'erreur semble provenir de ce code :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
| public class AffichageClientActivity extends MainActivity /*implements OnItemClickListener*/{
clientBDD cliBDD= new clientBDD(this);
ListView clientListe;
client cli = new client("","","","","","","",0,0);
private ArrayAdapter<String> ClientAdapter =null;
protected void onCreate(Bundle saveInstanceBundle){
super.onCreate(saveInstanceBundle);
setContentView(R.layout.listingclient);
clientListe = (ListView)findViewById(R.id.list);
//à faire passer en globale pour récupérer dans fidelité
//récupération de la valeur de l'EditText
Bundle objetbundle= this.getIntent().getExtras();
String nomduclient=objetbundle.getString("nomclient");
clientListe = (ListView)findViewById(R.id.list);
clientListe.setOnItemClickListener(ItemListener);
ClientAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1);
clientListe.setAdapter(ClientAdapter);
cliBDD.open();
cli = cliBDD.getClientwithNom(nomduclient);
if (cli != null){
//affichage du ou des client(s)
ClientAdapter.add(cli.getNom()+ " " + cli.getPrenom());
ClientAdapter.setNotifyOnChange(true);
}
else
{
Toast.makeText(this, "Ce client n'est pas enregistré dans la base, vérifier l'orthographe ou bien ajouter un nouveau client.", Toast.LENGTH_LONG).show();
}
cliBDD.close();
}
public String toString(){
String MonStringClient = null;
MonStringClient = cli.getNom() + cli.getPrenom();
return MonStringClient;}
private OnItemClickListener ItemListener = new OnItemClickListener(){
public void onItemClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
//recupération du nom du client
Intent versFidelite = new Intent(getApplicationContext(), FideliteActivity.class);
//versFidelite.putExtras("nomclient",nomclient);
startActivity(versFidelite);
}
};
} |
Comment puis je remédier à ça?
Merci d'avance :)