Tableau de java

Résolu
debutant :(( -  
bizu53 Messages postés 1274 Date d'inscription   Statut Membre Dernière intervention   - 19 févr. 2010 à 12:47
Bonjour,
svp je suis debutant en java et j'ai un prob de tableau et voila mon code:
public class s {

public static void main(String[] args) {
String [] tab0=null;
String tab1= "........." ;
String [] tab0= new String [tab0.length + 1];
for (int i= 0; i < tab.length; i++) {
tab0[i]= tab[i];
}

tab0[tab0.length - 1]= nouveauProduit;

tab= tab0;
for(int j=0;j<tab0.length;j++){
System.out.println(tab0[j]);
}
}}
A voir également:

3 réponses

bizu53 Messages postés 1274 Date d'inscription   Statut Membre Dernière intervention   861
 
Tu devrais coder dans un environnement de développement, ça aide beaucoup, ça détecte beaucoup d'erreur. (Pour ma part j'utilise NetBeans)

Celles de ton code en gras, et commentées :

public class s {

public static void main(String[] args) {
String[] tab0 = null;
String tab1 = ".........";
String[] tab0 = new String[tab0.length + 1]; //1) tab0 est déjà déclaré, 2) tab0 est null, donc il n'a pas d'attribut length.
for (int i = 0; i < tab.length; i++) { //tab n'est pas déclaré ni initialisé, n'existe donc pas
tab0[i] = tab[i]; //même erreur
}

tab0[tab0.length - 1] = nouveauProduit; //même erreur

tab = tab0; //même erreur
for (int j = 0; j < tab0.length; j++) {
System.out.println(tab0[j]);
}
}
}
1
debutant :((
 
et kan je le debugg ce code je recois l'exception suivante
Exception in thread "main" java.lang.NullPointerException
at s.main(s.java:9)
0
debutant :((
 
merci bizu53 ca ma aidé mais dit moi ce NetBeans on peut y travailler mai en codant java??
0
bizu53 Messages postés 1274 Date d'inscription   Statut Membre Dernière intervention   861
 
Oui, je l'utilise pour Java principalement (et C/C++ de temps en temps, et plus rarement encore PHP).
0