Problème de création d'objets
Bonjour,
J'ai un petit problème concernant la création d'un objet.
Voici ma classe principale (elle est censée créer 2 objets du type Polygone):
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| public class NetNest {
private float[] coordinatesA = {5, 2, 8, 3, 7, 8, 5, 5, 7, 10};
private float[] coordinatesB = {4, 4, 5, 2, 8, 7, 5, 9};
private Polygone polygoneA = null;
private Polygone polygoneB = null;
public static void main(String[] args) {
polygoneA = new Polygone(false, coordinatesA);
polygoneB = new Polygone(true, coordinatesB);
}
} |
Et voici maintenant la classe Polygone (placée dans le même projet sous eclipse mais dans un autre fichier):
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| public class Polygone {
private boolean isThePiece = false;
private float[] coordinates = null;
public Polygone(boolean isIt, float[] coord){
isThePiece = isIt;
for(int i = 0; i < coord.length; i++)
{
coordinates[i] = coord[i];
}
}
} |
J'ai une erreur aux lignes suivantes:
Code:
1 2
| polygoneA = new Polygone(false, coordinatesA);
polygoneB = new Polygone(true, coordinatesB); |
Cannot make a static reference to the non-static field polygoneA
Cannot make a static reference to the non-static field coordinatesA
Cannot make a static reference to the non-static field polygoneB
Cannot make a static reference to the non-static field coordinatesB
Quelqu'un peut-il ma'ider à résoudre ce problème svp? Faut-il importer un fichier dans l'autre? Comment faire?
Merci pour votre aide