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

Java Discussion :

[JAVA] erreur File cannot be null


Sujet :

Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Homme Profil pro
    Étudiant
    Inscrit en
    Septembre 2018
    Messages
    150
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Aude (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Septembre 2018
    Messages : 150
    Par défaut [JAVA] erreur File cannot be null
    bonjour,

    depuis peu j'ai une erreur dans mon programme que je ne comprends

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
     
    run:
    Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: File cannot be null
    	at java.xml/javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:199)
    	at My_Notam_Importer.ExtractionZone.evaluerDOM(ExtractionZone.java:61)
    	at My_Notam_Importer.MyWindow.jButton1ActionPerformed(MyWindow.java:236)
    	at My_Notam_Importer.MyWindow$1.actionPerformed(MyWindow.java:81)
    	at java.desktop/javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1967)
    	at java.desktop/javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2308)
    	at java.desktop/javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:405)
    	at java.desktop/javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:262)
    	at java.desktop/javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:279)
    	at java.desktop/java.awt.Component.processMouseEvent(Component.java:6614)
    	at java.desktop/javax.swing.JComponent.processMouseEvent(JComponent.java:3342)
    	at java.desktop/java.awt.Component.processEvent(Component.java:6379)
    	at java.desktop/java.awt.Container.processEvent(Container.java:2263)
    	at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:4990)
    	at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2321)
    	at java.desktop/java.awt.Component.dispatchEvent(Component.java:4822)
    	at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4919)
    	at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Container.java:4548)
    	at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Container.java:4489)
    	at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2307)
    	at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2769)
    	at java.desktop/java.awt.Component.dispatchEvent(Component.java:4822)
    	at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:772)
    	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
    	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
    	at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
    	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
    	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:95)
    	at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:745)
    	at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:743)
    	at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
    	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
    	at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:742)
    	at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
    	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
    	at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
    	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
    	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    	at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
    pourriez vous m'aider a mieux comprendre s'il vous plait?

  2. #2
    Rédacteur/Modérateur

    Avatar de bouye
    Homme Profil pro
    Information Technologies Specialist (Scientific Computing)
    Inscrit en
    Août 2005
    Messages
    6 901
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : Nouvelle-Calédonie

    Informations professionnelles :
    Activité : Information Technologies Specialist (Scientific Computing)
    Secteur : Agroalimentaire - Agriculture

    Informations forums :
    Inscription : Août 2005
    Messages : 6 901
    Billets dans le blog
    54
    Par défaut
    Le paramètre passé a la méthode qui contient une référence sur le fichier ou le chemin vers le fichier est null, il ne doit pas être null. Utilise le débogueur ou fait des impressions pour vérifier la valeur de tes paramètres dans My_Notam_Importer.ExtractionZone::evaluerDOM a la ligne 61.
    Merci de penser au tag quand une réponse a été apportée à votre question. Aucune réponse ne sera donnée à des messages privés portant sur des questions d'ordre technique. Les forums sont là pour que vous y postiez publiquement vos problèmes.

    suivez mon blog sur Développez.

    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning. ~ Rich Cook

  3. #3
    Membre confirmé
    Homme Profil pro
    Étudiant
    Inscrit en
    Septembre 2018
    Messages
    150
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Aude (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Septembre 2018
    Messages : 150
    Par défaut
    Bonsoir bouye,

    Merci pour votre réponse.
    Voici la méthode (la ligne 61 du message d'erreur précédent correspond ici a la ligne de code 17).
    Ce que je ne saisi pas, c'est que retour est souligné aussi en rouge dans mon IDE)
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
     
    public String evaluerDOM(File file, String expression, QName retour){
    		String texteCopie=null;
     
                    String zon1= "QRRCA";
                        String zon2= "QRDCA";
                            String zon3= "QRPCA";
                                String zon4= "QRTCA";
                            String zon5= "QWELW";
                        String zon6= "QWPLW";
                    String zon7= "QWULW";
    		try{
    			DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
                            docBuilderFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, ""); 
                            docBuilderFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_SCHEMA, ""); 
    			DocumentBuilder constructeur = docBuilderFactory.newDocumentBuilder();
    			Document document = constructeur.parse(file);
     
    			//création du XPath 
    			XPathFactory fabrique = XPathFactory.newInstance();
    			XPath xpath = fabrique.newXPath();
     
    			//évaluation de l'expression XPath
    			XPathExpression exp = xpath.compile(expression);
    			NodeList resultat = (NodeList) exp.evaluate(document,XPathConstants.NODESET); // récupère la liste de Node correspondant au xpath (donc des pre)
     
                            StringBuilder sb=new StringBuilder(); // pour faire la concaténation
                            for(int i=0; i<resultat.getLength(); i++ ) { // parcours
     
                                    Node pre = resultat.item(i); // on récupère le node d'index i 
                                    if (pre.getTextContent().contains(zon1)|| pre.getTextContent().contains(zon2) || pre.getTextContent().contains(zon3) || pre.getTextContent().contains(zon4) || pre.getTextContent().contains(zon5) || pre.getTextContent().contains(zon6) || pre.getTextContent().contains(zon7)){
                                        sb.append("\n");//ajout d'une ligne de séparation
    				sb.append(pre.getTextContent()); // concaténation du texte du node
                                    sb.append("\n");//ajout d'une ligne de séparation
                                    }
                            }
    			texteCopie=sb.toString(); // 
    		}catch(XPathExpressionException | ParserConfigurationException | SAXException | IOException xpee){//comment
    		}
    		return texteCopie;
    	}

  4. #4
    Rédacteur/Modérateur

    Avatar de bouye
    Homme Profil pro
    Information Technologies Specialist (Scientific Computing)
    Inscrit en
    Août 2005
    Messages
    6 901
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : Nouvelle-Calédonie

    Informations professionnelles :
    Activité : Information Technologies Specialist (Scientific Computing)
    Secteur : Agroalimentaire - Agriculture

    Informations forums :
    Inscription : Août 2005
    Messages : 6 901
    Billets dans le blog
    54
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Document document = constructeur.parse(file);
    Et donc il faudrait vérifier que la valeur de file (qui est un paramètre de ta méthode) n'est pas null.
    Merci de penser au tag quand une réponse a été apportée à votre question. Aucune réponse ne sera donnée à des messages privés portant sur des questions d'ordre technique. Les forums sont là pour que vous y postiez publiquement vos problèmes.

    suivez mon blog sur Développez.

    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning. ~ Rich Cook

  5. #5
    Membre confirmé
    Homme Profil pro
    Étudiant
    Inscrit en
    Septembre 2018
    Messages
    150
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Aude (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Septembre 2018
    Messages : 150
    Par défaut
    désolé je m'en sors pas je ne comprends pas..

  6. #6
    Rédacteur/Modérateur

    Avatar de bouye
    Homme Profil pro
    Information Technologies Specialist (Scientific Computing)
    Inscrit en
    Août 2005
    Messages
    6 901
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : Nouvelle-Calédonie

    Informations professionnelles :
    Activité : Information Technologies Specialist (Scientific Computing)
    Secteur : Agroalimentaire - Agriculture

    Informations forums :
    Inscription : Août 2005
    Messages : 6 901
    Billets dans le blog
    54
    Par défaut
    Je ne vois pas trop ce qu'il est possible d'ajouter. Tu passes la valeur null dans une méthode qui ne supporte pas cette valeur, donc ça plante avec une erreur. Corrige ton code pour mettre une valeur correcte dans cette variable.
    Merci de penser au tag quand une réponse a été apportée à votre question. Aucune réponse ne sera donnée à des messages privés portant sur des questions d'ordre technique. Les forums sont là pour que vous y postiez publiquement vos problèmes.

    suivez mon blog sur Développez.

    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning. ~ Rich Cook

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 1
    Dernier message: 08/06/2009, 16h22
  2. Réponses: 2
    Dernier message: 24/06/2008, 16h30
  3. Message d`erreur " error:cannot read : src/main/org/pache/tools/bzip2/*.java "
    Par wiss20000 dans le forum RedHat / CentOS / Fedora
    Réponses: 0
    Dernier message: 09/11/2007, 15h36
  4. Réponses: 9
    Dernier message: 03/06/2007, 21h40
  5. [Hibernate] erreur database product name cannot be null
    Par enimiste dans le forum Hibernate
    Réponses: 4
    Dernier message: 24/04/2007, 19h07

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