Salut à tous,

J'ai un problème dans une de mes fonctions qui est censée retourner une valeur. Je n'arrive pas du tout à comprendre pourquoi ça ne marche pas, alors ça serait sympa si quelqu'un pouvait m'aider. Merci.

Voici la classe qui représente une lettre :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
public class Letter {
    public char MyLetter = ' ';
    public String MyBinary = " ";
 
    // create the constructor
    public Letter (char myLetter, String myBinary)
    {
        MyLetter = myLetter;
        MyBinary = myBinary;
    }
}
Voici la classe qui crée une liste de lettres :
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
public class AsciiTable {
    private List<Letter> asciiTable;
 
    public List<Letter> getAsciiTable() {
        return asciiTable;
    }
 
    // create the constructor
    public AsciiTable()
    {
        asciiTable = new LinkedList<Letter>();
 
        asciiTable.add(0,new Letter(' ',"00100000"));
        asciiTable.add(1,new Letter('!',"00100001"));
    }
}
Voici une méthode qui s'occupe de la logique qui retourne les valeurs demandées de la lettre :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
 public char returnTextLetter(String binStr)
    {
        for (Letter item : asciiTable.getAsciiTable())
        {
            if (item.MyBinary == binStr)
            {
                return item.MyLetter;
            }
        }
        return ' ';
    }
et voici la fonction principale qui utilise la logique, en cliquant sur un bouton :

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 void buttonBinaryToTextClick(View v){
        //do something when the button is clicked
        Button button = (Button) v;
        newText = "";
        //detect if the binary box is empty or not, if is not empty so this enter in the if
        String strBinaryBox = BoxBinary.getText().toString();
            try
            {
                for (int i = 0; i < strBinaryBox.length(); i = i + 8)
                {
                    newText += logic.returnTextLetter(strBinaryBox.substring(i, 8));
                }
                BoxText.setText(newText);
            }
            catch (Exception e)
            {
                BoxBinary.setText("The binary numbers need to be divised by 8");
            }
    }