Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
2303 connectés 

  FORUM HardWare.fr
  Programmation
  Java

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

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

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

n°1217905
nicolasf
Posté le 07-10-2005 à 17:20:12  profilanswer
 

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
mood
Publicité
Posté le 07-10-2005 à 17:20:12  profilanswer
 

n°1217962
bartleby
Posté le 07-10-2005 à 18:06:41  profilanswer
 

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

n°1218550
mars47058
Posté le 08-10-2005 à 23:30:44  profilanswer
 

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é !

n°1219274
nicolasf
Posté le 10-10-2005 à 10:03:39  profilanswer
 

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


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  Java

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

 

Sujets relatifs
ActionScript + invite de commande windows [résolu][1/2 RESOLU] Problème installation Tomcat 5
[css][resolu] centrer un menu.vfw.h et clipboard [resolu]
[RESOLU] Probleme d'import pour librairie POIvariable
[resolu] Duplication de STDOUTOutil de travail collaboratif sur Eclipse genre CVS ? [résolu]
[J2EE][Tomcat] ServletException[Résolu][JS] document.write jamais nécéssaire?[Résolu]
Plus de sujets relatifs à : [RESOLU] ereur non-static variable.........


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR