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

avec Java Discussion :

Contrôle d'une String et valeur de retour


Sujet :

avec Java

  1. #21
    Membre expert

    Homme Profil pro
    Consultant informatique
    Inscrit en
    Janvier 2004
    Messages
    2 301
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : Consultant informatique
    Secteur : Finance

    Informations forums :
    Inscription : Janvier 2004
    Messages : 2 301
    Points : 3 675
    Points
    3 675
    Par défaut
    Citation Envoyé par tchize_ Voir le message
    pill_S: c'est pas la forme aujourd'hui: une boucle avec un switch pour pas faire un if-then-else???
    LOL

    oui, c'était plus pour reprendre l'idée de sa boucle, mais je te concède que c'est une ABERRATION et je te rassure, je n'écris jamais ce genre de mocheté dans la vraie vie

  2. #22
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2011
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mai 2011
    Messages : 2
    Points : 8
    Points
    8
    Par défaut
    Ok beh alors tu as pas besoin de faire deux fois les if... il te suffit de faire un fonction avec tes if genre transcription. Et tu l'appelle dans ta boucle pour créer ta nouvelle chaîne traduite...

    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
     
    private String transcriptionUnChar(char monChar){
          String transcription="";
     
         // Tous tes if... pour donner la valeur de ta traduction en fonction du char
     
     
      return transcription;
    }
     
    private String transcriptionTab(char[] monTab){
     
    String traductionMot="";
     
    for (int i = 0 ; i< monTab.length){
     traductionMot+=transcriptionUnChar(monTab[i]);
    }
     
    return traductionMot;
    }
    Un truc dans ce gout la... J'ai pas testé mais c'est l'idée, si j'ai bien compris ton problème...

  3. #23
    Membre régulier Avatar de Tora21
    Homme Profil pro
    Développeur("Java"); //Débutant
    Inscrit en
    Mai 2011
    Messages
    140
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Côte d'Or (Bourgogne)

    Informations professionnelles :
    Activité : Développeur("Java"); //Débutant

    Informations forums :
    Inscription : Mai 2011
    Messages : 140
    Points : 116
    Points
    116
    Par défaut
    Hum, comment je peut faire pour accéder à une classe interne?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
    class A
    {
        class B
        {
        }
    }
    et de l'autre coté j'ai ma classe avec les méthode de traduction C.
    Je souhaiterais accéder à B depuis C.

    alors j'ai vu le code suivant:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    A.B aB = (new A).new B();
    mais sa ne fonctionne pas, dès le début du code.

    édit: Nan nan sa marche c'est bon, je suis juste bourré, j'essayais de mettre un variable aA objet instance de A à la place de A dans la formule précédente.

  4. #24
    Membre régulier Avatar de Tora21
    Homme Profil pro
    Développeur("Java"); //Débutant
    Inscrit en
    Mai 2011
    Messages
    140
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Côte d'Or (Bourgogne)

    Informations professionnelles :
    Activité : Développeur("Java"); //Débutant

    Informations forums :
    Inscription : Mai 2011
    Messages : 140
    Points : 116
    Points
    116
    Par défaut
    Serais-t-il possible de rendre ta méthode static tchize_? parce que sinon ça m'oblige à passer les valeur d'une classe à une autre et je me tape une erreur que je n'arrive pas à résoudre et qui m'a déjà posé des problème pour d'autre truc, Exception in thread "main" java.lang.StackOverflowError.

  5. #25
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 482
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 482
    Points : 48 807
    Points
    48 807
    Par défaut
    stackoverflow -> t'es en boucle infinie:

    quelle erreur ca te pose que ces méthodes ne soient pas statiques? tu peux les mettre en static sans problème, tant que les méthodes restent sans état, l'instance n'est pas nécessaire.

  6. #26
    Membre régulier Avatar de Tora21
    Homme Profil pro
    Développeur("Java"); //Débutant
    Inscrit en
    Mai 2011
    Messages
    140
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Côte d'Or (Bourgogne)

    Informations professionnelles :
    Activité : Développeur("Java"); //Débutant

    Informations forums :
    Inscription : Mai 2011
    Messages : 140
    Points : 116
    Points
    116
    Par défaut
    StackOverFlow--> ok

    Hum statique, parce que je pensais que StackOverFlow était lié à une mauvaise instanciation d'une de mes classes. Donc pour contourner je pensais en static.
    Mais le problème de l'erreur compris pour moi, je vai me tourner vers le for de ta méthode qui je crois tourne dans le vide.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    for (char c : s.toCharArray ())
    {
    	sb.append (convertCharacter (c));
    }
    édit: Visiblement ce n'est pas ça non plus, je suis un peu pomé.

  7. #27
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 482
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 482
    Points : 48 807
    Points
    48 807
    Par défaut
    si vous postiez la stacktrace de votre erreur?

  8. #28
    Membre régulier Avatar de Tora21
    Homme Profil pro
    Développeur("Java"); //Débutant
    Inscrit en
    Mai 2011
    Messages
    140
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Côte d'Or (Bourgogne)

    Informations professionnelles :
    Activité : Développeur("Java"); //Débutant

    Informations forums :
    Inscription : Mai 2011
    Messages : 140
    Points : 116
    Points
    116
    Par défaut
    Voici l'erreur:
    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
     
    Exception in thread "main" java.lang.StackOverflowError
    	at javax.swing.text.StyleContext$SmallAttributeSet.equals(Unknown Source)
    	at java.util.WeakHashMap.eq(Unknown Source)
    	at java.util.WeakHashMap.get(Unknown Source)
    	at java.util.Collections$SynchronizedMap.get(Unknown Source)
    	at javax.swing.text.StyleContext.getImmutableUniqueSet(Unknown Source)
    	at javax.swing.text.StyleContext.addAttributes(Unknown Source)
    	at javax.swing.text.AbstractDocument$AbstractElement.addAttributes(Unknown Source)
    	at javax.swing.text.AbstractDocument$AbstractElement.<init>(Unknown Source)
    	at javax.swing.text.AbstractDocument$LeafElement.<init>(Unknown Source)
    	at javax.swing.text.AbstractDocument$BidiElement.<init>(Unknown Source)
    	at javax.swing.text.AbstractDocument.<init>(Unknown Source)
    	at javax.swing.text.AbstractDocument.<init>(Unknown Source)
    	at javax.swing.text.PlainDocument.<init>(Unknown Source)
    	at javax.swing.text.PlainDocument.<init>(Unknown Source)
    	at javax.swing.text.DefaultEditorKit.createDefaultDocument(Unknown Source)
    	at javax.swing.plaf.basic.BasicTextUI.installUI(Unknown Source)
    	at javax.swing.JComponent.setUI(Unknown Source)
    	at javax.swing.text.JTextComponent.setUI(Unknown Source)
    	at javax.swing.text.JTextComponent.updateUI(Unknown Source)
    	at javax.swing.text.JTextComponent.<init>(Unknown Source)
    	at javax.swing.JTextField.<init>(Unknown Source)
    	at javax.swing.JTextField.<init>(Unknown Source)
    	at package.PanelLabel.<init>(PanelLabel.java:20)
    	at package.FenetrePrincipale.<init>(FenetrePrincipale.java:16)
    	at package.TradTool.<init>(TradTool.java:41)
    	at package.FenetrePrincipale.<init>(FenetrePrincipale.java:20)
    	at package.TradTool.<init>(TradTool.java:41)
    et on retrouve "at package.FenetrePrincipale.<init>(FenetrePrincipale.java:20)
    at package.TradTool.<init>(TradTool.java:41)"
    sur encore beaucoup de ligne sans variante.

  9. #29
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 482
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 482
    Points : 48 807
    Points
    48 807
    Par défaut
    t'as une récusrsion infinie de constructeur:
    TradTool crée un FenetrePrincipal qui crée un TradTool qui crée un FenetrePrincipal etc

  10. #30
    Membre régulier Avatar de Tora21
    Homme Profil pro
    Développeur("Java"); //Débutant
    Inscrit en
    Mai 2011
    Messages
    140
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Côte d'Or (Bourgogne)

    Informations professionnelles :
    Activité : Développeur("Java"); //Débutant

    Informations forums :
    Inscription : Mai 2011
    Messages : 140
    Points : 116
    Points
    116
    Par défaut
    Ben dans ma classe FenetrePrincipale, j'ai un:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
    private TradTool			unTradTool			= new TradTool ();
     
    public FenetrePrincipale  TradTool aTrad)
    	{
    		this.unTradTool = aTrad;
    	}
    et dans trad j'ai:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
    public FenetrePrincipale	fp	= new FenetrePrincipale ();
     
    public TradTool (FenetrePrincipale aFp)
    {
    	this.fp = aFp;
    }
    qu'est-ce que j'ai loupé et qui m'a pas loupé ?

  11. #31
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 482
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 482
    Points : 48 807
    Points
    48 807
    Par défaut
    les deux new font implictement partie du constructeur. Votre code équivaut à

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    private TradTool			unTradTool;
     
    public FenetrePrincipale (TradTool aTrad)
    	{
                    unTradTool = new TradTool ();
    		this.unTradTool = aTrad;
    	}
    Pareil pour l'autre. La boucle est assez évidente à partir de là (new appelle new qui appelle new qui ....


    Remplacez par
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    private TradTool			unTradTool;
     
    public FenetrePrincipale  (TradTool aTrad)
    	{
    		this.unTradTool = aTrad;
    	}
    idem pour l'autre classe.

  12. #32
    Membre régulier Avatar de Tora21
    Homme Profil pro
    Développeur("Java"); //Débutant
    Inscrit en
    Mai 2011
    Messages
    140
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Côte d'Or (Bourgogne)

    Informations professionnelles :
    Activité : Développeur("Java"); //Débutant

    Informations forums :
    Inscription : Mai 2011
    Messages : 140
    Points : 116
    Points
    116
    Par défaut
    Je suis d'accord mais ce que je ne comprend pas, c'est que mon unTradTool, s'il n'est pas instancié ne devrait pas exister non?

    Parce que lorsque je lance le programme après votre modification, il me met un null pointeur sur la ligne:

    unPanellabel.getLabelResult ().setText (unTradTool.getTextFinal ());

    Donc de ce que je comprend il ne trouve pas unTradTool.

    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
    43
    44
    45
    46
    47
    48
     
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    	at package.FenetrePrincipale$GestionnaireAction.actionPerformed(FenetrePrincipale.java:64)
    	at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    	at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
    	at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    	at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    	at javax.swing.AbstractButton.doClick(Unknown Source)
    	at javax.swing.plaf.basic.BasicRootPaneUI$Actions.actionPerformed(Unknown Source)
    	at javax.swing.SwingUtilities.notifyAction(Unknown Source)
    	at javax.swing.JComponent.processKeyBinding(Unknown Source)
    	at javax.swing.KeyboardManager.fireBinding(Unknown Source)
    	at javax.swing.KeyboardManager.fireKeyboardAction(Unknown Source)
    	at javax.swing.JComponent.processKeyBindingsForAllComponents(Unknown Source)
    	at javax.swing.JComponent.processKeyBindings(Unknown Source)
    	at javax.swing.JComponent.processKeyEvent(Unknown Source)
    	at java.awt.Component.processEvent(Unknown Source)
    	at java.awt.Container.processEvent(Unknown Source)
    	at java.awt.Component.dispatchEventImpl(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.KeyboardFocusManager.redispatchEvent(Unknown Source)
    	at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(Unknown Source)
    	at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(Unknown Source)
    	at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(Unknown Source)
    	at java.awt.DefaultKeyboardFocusManager.dispatchEvent(Unknown Source)
    	at java.awt.Component.dispatchEventImpl(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Window.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    	at java.awt.EventQueue.access$000(Unknown Source)
    	at java.awt.EventQueue$1.run(Unknown Source)
    	at java.awt.EventQueue$1.run(Unknown Source)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
    	at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
    	at java.awt.EventQueue$2.run(Unknown Source)
    	at java.awt.EventQueue$2.run(Unknown Source)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
    	at java.awt.EventQueue.dispatchEvent(Unknown Source)
    	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.run(Unknown Source)
    édit: En plus je me rend compte que c'est exactement le même délire sur un autre programme que je fais actuellement, et j'avais changé complètement de structure à cause de ça.
    résoudre ça m'aiderais beaucoup pour l'autre.

    voici le lien de référence à l'autre problème que j'avais eu:
    http://www.developpez.net/forums/d10.../gouffre-code/

  13. #33
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 482
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 482
    Points : 48 807
    Points
    48 807
    Par défaut
    vous ne pouvez pas faire ça

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    public class X {
       Y y = new Y();
    }
    public class Y {
       X x= new X();
    }
    Puisque comme vous le voyez vous avec une boucle là.


    vous devez travailler en deux temps et passer les paramètres correctement à vos constructeurs / setters : si vous voulez que deux instances de x et y se voient mutuellement.

    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
     
    public class X {
       Y y;
       public X(Y y){
          this.y = y;
       }
    }
     
     
    public class Y {
       X x;
       public Y(){
           x = new X(this);
       }
    }
     
    //main:
     
      Y y = new Y();
    Si vous avez desn ullpointerexception c'est que vous avez oublié la partie initialisation. Il faudra de toutes façons que vous décidiez de l'ordre dans lequel vous voulez instancier vos classes.

  14. #34
    Membre régulier Avatar de Tora21
    Homme Profil pro
    Développeur("Java"); //Débutant
    Inscrit en
    Mai 2011
    Messages
    140
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Côte d'Or (Bourgogne)

    Informations professionnelles :
    Activité : Développeur("Java"); //Débutant

    Informations forums :
    Inscription : Mai 2011
    Messages : 140
    Points : 116
    Points
    116
    Par défaut
    okay d'accord je vais ordonner tous ça voir ce que ça donne.

  15. #35
    Membre régulier Avatar de Tora21
    Homme Profil pro
    Développeur("Java"); //Débutant
    Inscrit en
    Mai 2011
    Messages
    140
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Côte d'Or (Bourgogne)

    Informations professionnelles :
    Activité : Développeur("Java"); //Débutant

    Informations forums :
    Inscription : Mai 2011
    Messages : 140
    Points : 116
    Points
    116
    Par défaut
    Bon ben c'est nickel, merci pour l'aide à tous le monde, et tchize_ pour les conseils de fin qui comblent mon manque de savoir sur certain points.

    En plus de finir mon projet de taf, je me suis fait une une version vierge du programme, au format le plus simple, vide de caractère, on s'est jamais ça peut servir.

    Si vous voulez les sources (vierge et simples) mp moi.

+ Répondre à la discussion
Cette discussion est résolue.
Page 2 sur 2 PremièrePremière 12

Discussions similaires

  1. [Débutant] Convertir une "String" en valeur "numeric"
    Par caroe.lavoie dans le forum ASP.NET
    Réponses: 3
    Dernier message: 09/08/2013, 11h17
  2. Valeur de retour d'une procédure stockée
    Par Rudyweb dans le forum MFC
    Réponses: 4
    Dernier message: 25/02/2005, 17h52
  3. [VB6] Valeur de retour pour une Form
    Par preverse dans le forum VB 6 et antérieur
    Réponses: 3
    Dernier message: 17/08/2004, 17h16
  4. Valeur de retour d'une procédure externe
    Par elekis dans le forum x86 32-bits / 64-bits
    Réponses: 4
    Dernier message: 16/04/2004, 16h45
  5. Pourquoi une seule valeur de retour pour les fonctions ?
    Par Bruno75 dans le forum Langages de programmation
    Réponses: 33
    Dernier message: 18/01/2004, 13h58

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