@id_aspin
Good guy

[Ошибки и вылеты конвертера систем счисления]Как избежать вылеты и установить работоспособность программы?

Код из лайоута:
<TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Конвертер систем счисления:"
            android:id="@+id/textView6"
            android:gravity="center_horizontal"
            android:password="false" />
 
        <LinearLayout
            android:orientation="horizontal"
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:layout_gravity="center_horizontal"
            android:background="#fff">
 
            <EditText
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:inputType="textCapCharacters"
                android:gravity="center"
                android:id="@+id/editText2"
                android:textSize="40dp"
                android:layout_weight="0.5"
                android:text="23E" />
 
            <EditText
                android:layout_width="fill_parent"
                android:layout_height="match_parent"
                android:id="@+id/editText"
                android:inputType="number"
                android:text="16"
                android:layout_weight="2"
                android:background="#ccc" />
        </LinearLayout>
 
        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_gravity="center_horizontal"
            android:layout_height="wrap_content">
 
            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:id="@+id/editText3"
                android:text="606"
                android:textSize="40dp"
                android:textColor="#333"
                android:layout_weight="0.5"
                android:gravity="center"
                 />
 
            <EditText
                android:layout_width="fill_parent"
                android:layout_height="match_parent"
                android:id="@+id/editText4"
                android:inputType="number"
                android:text="10"
                android:background="#ccc"
               android:layout_weight="2"
                />
 
        </LinearLayout>
 
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Ковертировать"
            android:id="@+id/button23"
            android:onClick="onbsc2"
            android:layout_gravity="center_horizontal" />


Код обработчиков Activity:

public void onbsc2(View view)
    {
 
            inTV = (EditText) findViewById(R.id.editText2);
        String ENter = String.valueOf(inTV.getText());
        ENter.replaceAll("А", "A");
        ENter.replaceAll("В", "B");
        ENter.replaceAll("С", "C");
        ENter.replaceAll("Е ", "E");
        ENter.replaceAll("К ", "K");
        ENter.replaceAll("М ", "M");
        ENter.replaceAll("Н ", "H");
        ENter.replaceAll("О ", "O");
        ENter.replaceAll("Р ", "P");
        ENter.replaceAll("Т ", "T");
        ENter.replaceAll("У ", "Y");
        ENter.replaceAll("Х ", "X");
 
        if (ENter== "") {
                ENter = "0";inTV.setText(ENter);
            }
 
            inTV = (EditText) findViewById(R.id.editText);
            String ENter2 = String.valueOf(inTV.getText());
            ENter2.replaceAll(" ", "");
            if (ENter2 == "") {
                ENter2 = "2";inTV.setText(ENter2);
            }
 
            inTV = (EditText) findViewById(R.id.editText4);
            String ENter3 = String.valueOf(inTV.getText());
            ENter3.replaceAll(" ", "");
            if (ENter3.replaceAll(" ", "") == "") {
                ENter3 = "10";inTV.setText(ENter3);
            }
 
        if (Integer.parseInt(ENter)>=0)
        {
            
 
                    if (Integer.parseInt(ENter3)==10)
                    {
                        outTV = (TextView) findViewById(R.id.editText3);
                        outTV.setText(convertto10(ENter,Integer.parseInt(ENter2)));
                    }
 
            
        }
 
    }

и конвертер
private static String convertto10(String get, int cc) {
        String exit="0";
        String posix="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
 
        int length = get.length(),j=0;
 
        try {
 
        for (int i=length-1;i>=0;i--)
        {
            exit = String.valueOf( Integer.parseInt(exit) + posix.indexOf(get.substring(i,i+1))*Math.pow(cc,length-i) );
        }
 
        }catch (Throwable sa){exit="Oops :C";}
        return exit;
    }


1) При запуске программы, нажатии на "Конвертировать" программа вылетает.
2) При переводе из двоичной системы счисления в TextView выводит "Oops :C"
Почему?

v3kaqf.jpg
  • Вопрос задан
  • 2294 просмотра
Пригласить эксперта
Ответы на вопрос 2
@onepavel
Консультация и разработка мобильных приложений
Лог ошибки подсказывает вам место и причину ошибки.
Место: MainActivity.onbsc2 строка 1026
Причина: NumberFormatException, Invalid int 23E
скорее всего это Integer.parseInt не смог строку перевести в число
Ответ написан
Комментировать
Applez
@Applez
Разраб
Exceptions, разве нет?
В смысле try catch finally.
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы