[RESOLU] ereur non-static variable.........

ereur non-static variable......... [RESOLU] - Java - Programmation

Marsh Posté le 07-10-2005 à 17:20:12    

Alors voila, j'ai une classe qui est toute courte et qui contient pas grand chose, mais quand je compile, j'ai l'erreur suivante qui apparait :

Citation :

Prog.java:26 non-static variable uneMib cannot be referenced from a static context  
uneMib=loadMib(f);
Prog.java:26 non-static methode loadMib(java.io.file) cannot be referenced from a static context  
uneMib=loadMib(f);


Mon programme est le suivant :

Citation :

import java.util.*;
import java.io.*;
import java.lang.Throwable;
import java.awt.*;
 
import net.percederberg.mibble.* ;
import net.percederberg.mibble.snmp.* ;
import net.percederberg.mibble.value.* ;
import net.percederberg.mibble.type.*;
 
 
public class Prog
{  
 private Mib uneMib;
 
/* Method for loading a mib file  
**  
*/
public Mib loadMib(File file1) throws IOException, MibLoaderException {
   MibLoader  loader = new MibLoader();
    loader.addDir(file1.getParentFile());
    return loader.load(file1);
}
 
}


Alors bien sur quand je declare mon attribut et ma methode en static, je n'ai plus de probleme.
Seulement, ça m'empeche de realiser d'autres choses par la suite et donc j'aimerais trouver une autre solution.
Si qq'un a une idee, je le remercie grandement !!


Message édité par nicolasf le 10-10-2005 à 10:04:09
Reply

Marsh Posté le 07-10-2005 à 17:20:12   

Reply

Marsh Posté le 07-10-2005 à 18:06:41    

Fait moi voir ta method main.
 
Je pense que tu tentes d'acceder depuis le main (static en general) a ton object.

Reply

Marsh Posté le 08-10-2005 à 23:30:44    

http://forum.hardware.fr/hardwaref [...] 8709-1.htm
vois le paragraphe "Le piège du static void main" redigé par sicram
moi, ca ma aidé !

Reply

Marsh Posté le 10-10-2005 à 10:03:39    

Merci pour le lien.
ça m'a bien aidé a comprendre

Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed