IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

API standards et tierces Java Discussion :

[FOP] [ERROR] non-static variable this cannot be referenced from a static context


Sujet :

API standards et tierces Java

  1. #1
    Membre à l'essai
    Inscrit en
    Juin 2005
    Messages
    42
    Détails du profil
    Informations forums :
    Inscription : Juin 2005
    Messages : 42
    Points : 18
    Points
    18
    Par défaut [FOP] [ERROR] non-static variable this cannot be referenced from a static context
    bonjour, je voudrais essayer FOP

    mon programme est le suivant :
    import javax.xml.parsers.*;
    import org.w3c.dom.*;
    import org.xml.sax.*;
    import javax.xml.transform.*;
    import javax.xml.transform.sax.*;
    import javax.xml.transform.dom.*;
    import javax.xml.transform.stream.*;
    import java.io.*;
    import java.util.*;
    import org.apache.fop.apps.Driver;

    /**
    *
    * @author fmunoz
    */
    public class Main {

    /** Creates a new instance of Main */
    public Main() {

    }

    public static void creerPDF(String xml, String xsl, String pdf) throws Exception{
    // création du résultat (pdf)
    Driver driver = new Driver();
    driver.setRenderer(Driver.RENDER_PDF);
    driver.setOutputStream(new java.io.FileOutputStream(pdf));
    Result resultat = new SAXResult(driver.getContentHandler());
    // récupération de la source xml
    Source source = new StreamSource(xml);
    // création du transformer en fonction du xsl
    Source style = new StreamSource(xsl);
    TransformerFactory transformerFactory = TransformerFactory.newInstance();
    Transformer transformer = transformerFactory.newTransformer(style);
    // transformation
    transformer.transform(source, resultat);
    }

    /**
    * @param args the command line arguments
    */
    public static void main(String[] args) {
    try{
    this.creerPDF("donneeABC.xml", "verifABC.xsl", "pdfABC.pdf");
    }catch(Exception e){e.printStackTrace();}

    }

    }
    mais une erreur apparait :
    non-static variable this cannot be referenced from a static context
    pouvais vous m'expliquer cette erreur.

    merci :)

  2. #2
    Membre expérimenté Avatar de yann2
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mai 2004
    Messages
    897
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Mai 2004
    Messages : 897
    Points : 1 635
    Points
    1 635
    Par défaut
    bonjour

    Tu ne peux pas utiliser la référence this dans une méthode static (main et creerPDF)

    Il faut changer le main :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    public static void main(String[] args) {
             try{
                    creerPDF("donneeABC.xml", "verifABC.xsl", "pdfABC.pdf");
             }catch(Exception e){e.printStackTrace();}
     
         }
    bon courage

  3. #3
    Membre à l'essai
    Inscrit en
    Juin 2005
    Messages
    42
    Détails du profil
    Informations forums :
    Inscription : Juin 2005
    Messages : 42
    Points : 18
    Points
    18
    Par défaut
    le compilateur me répond

    java.lang.NoClassDefFoundError: org/apache/avalon/framework/logger/Logger

    at xmlbeansfop.Main.creerPDF(Main.java:44)

    at xmlbeansfop.Main.main(Main.java:63)

    Exception in thread "main"

    Java Result: 1
    tu pense que c'est du à quoi?

    merci

  4. #4
    in
    in est déconnecté
    Membre expérimenté Avatar de in
    Profil pro
    Inscrit en
    Avril 2003
    Messages
    1 612
    Détails du profil
    Informations personnelles :
    Localisation : France, Finistère (Bretagne)

    Informations forums :
    Inscription : Avril 2003
    Messages : 1 612
    Points : 1 718
    Points
    1 718
    Par défaut
    ben il ne trouve pas la classe Logger ...

    as tu chargé la librairie ? un jar style log4j je suppose ...
    "If email had been around before the telephone was invented, people would have said, 'Hey, forget email! With this new telephone invention I can actually talk to people!"

    Besoin d'une nouvelle méthode pour développer ? -> http://www.la-rache.com/

  5. #5
    Membre à l'essai
    Inscrit en
    Juin 2005
    Messages
    42
    Détails du profil
    Informations forums :
    Inscription : Juin 2005
    Messages : 42
    Points : 18
    Points
    18
    Par défaut
    je n'ai pas de jar de ce nom dans les sources de FOP
    ou pourrais le trouver svp?

    (pour l'instant j'ai que le jar fop.jar)

    merci

  6. #6
    Expert éminent sénior
    Avatar de sinok
    Profil pro
    Inscrit en
    Août 2004
    Messages
    8 765
    Détails du profil
    Informations personnelles :
    Âge : 43
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Août 2004
    Messages : 8 765
    Points : 12 977
    Points
    12 977
    Par défaut
    Pour moi ce serait plutôt du Avalon LogKit que Log4j...
    Hey, this is mine. That's mine. All this is mine. I'm claiming all this as mine. Except that bit. I don't want that bit. But all the rest of this is mine. Hey, this has been a really good day. I've eaten five times, I've slept six times, and I've made a lot of things mine. Tomorrow, I'm gonna see if I can't have sex with something.

  7. #7
    Expert éminent
    Avatar de GrandFather
    Inscrit en
    Mai 2004
    Messages
    4 587
    Détails du profil
    Informations personnelles :
    Âge : 54

    Informations forums :
    Inscription : Mai 2004
    Messages : 4 587
    Points : 7 103
    Points
    7 103
    Par défaut
    Bonjour,

    assure-toi d'avoir dans ton classpath fop.jar, avalon.jar et batik.jar ; d'autre part, inspire-toi des exemples figurant dans cette page : http://xmlgraphics.apache.org/fop/0.20.5/embedding.html
    FAQ XML
    ------------
    « Le moyen le plus sûr de cacher aux autres les limites de son savoir est de ne jamais les dépasser »
    Giacomo Leopardi

  8. #8
    Membre à l'essai
    Inscrit en
    Juin 2005
    Messages
    42
    Détails du profil
    Informations forums :
    Inscription : Juin 2005
    Messages : 42
    Points : 18
    Points
    18
    Par défaut
    j'ai monté batik.jar et ça marche

  9. #9
    Membre à l'essai
    Inscrit en
    Juin 2005
    Messages
    42
    Détails du profil
    Informations forums :
    Inscription : Juin 2005
    Messages : 42
    Points : 18
    Points
    18
    Par défaut
    ça sert à quoi le logger?

Discussions similaires

  1. Non-static variable cannot be referenced from a static context
    Par otylio dans le forum Débuter avec Java
    Réponses: 4
    Dernier message: 23/11/2018, 15h42
  2. Réponses: 4
    Dernier message: 12/02/2015, 10h27
  3. non-static method cannot be referenced from a static context
    Par Spawny123 dans le forum Débuter avec Java
    Réponses: 3
    Dernier message: 04/03/2010, 21h38
  4. Erreur : cannot be referenced from a static context
    Par Belegkarnil dans le forum Langage
    Réponses: 2
    Dernier message: 21/12/2005, 07h24
  5. Réponses: 3
    Dernier message: 05/12/2005, 10h27

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo