Answer the question
In order to leave comments, you need to log in
[Errors and crashes of the number system converter] How to avoid crashes and establish the program's performance?
Code from layout:
<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" />
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;
}
Answer the question
In order to leave comments, you need to log in
The error log tells you the location and cause of the error.
Location: MainActivity.onbsc2 line 1026
Cause: NumberFormatException, Invalid int 23E
most likely it's Integer.parseInt could not convert string to number
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question