-2
I am beginner and every time I try to make my application run from error, please help me I have to finish this as soon as possible
package com.example.chuveiroappuva;
import com.example.chuveiroappuva.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioButton;
public class ChuveiroAppUVA extends Activity {
EditText editText1;
EditText editText2;
EditText editText3;
EditText editText4;
CheckBox checkBox1;
RadioButton radio0;
RadioButton radio1;
RadioButton radio2;
RadioButton radio3;
RadioButton radio4;
Button button1;
Button button2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_chuveiro_app_uv);
editText1 = (EditText) findViewById(R.id.editText1);
editText2 = (EditText) findViewById(R.id.editText2);
editText3 = (EditText) findViewById(R.id.editText3);
editText4 = (EditText) findViewById(R.id.editText4);
checkBox1 = (CheckBox) findViewById(R.id.checkBox1);
radio0 = (RadioButton) findViewById(R.id.radio0);
radio1 = (RadioButton) findViewById(R.id.radio1);
radio2 = (RadioButton) findViewById(R.id.radio2);
radio3 = (RadioButton) findViewById(R.id.radio3);
radio4 = (RadioButton) findViewById(R.id.radio4);
button1 = (Button) findViewById(R.id.button1);
button2 = (Button) findViewById(R.id.button2);
button1.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View arg0){
}
});
int numero =0, quantidade =0, banhos = 0;
numero = Integer.parseInt(editText1.getText().toString());
quantidade = Integer.parseInt(editText2.getText().toString());
banhos = numero * quantidade;
editText3.setText(String.valueOf(banhos));
button2.setOnClickListener(new OnClickListener(){
private boolean eletrico;
@Override
public void onClick(View arg0){
@SuppressWarnings("unused")
int numero =0, quantidade =0, banhos = 0;
double cm;
numero = Integer.parseInt(editText1.getText().toString());
quantidade = Integer.parseInt(editText2.getText().toString());
//Verificação de Chuveiro
if(checkBox1.isChecked()){
setEletrico(true);
}
else{
setEletrico(false);
}
//Processamento
quantidade = numero * banhos;
editText3.setText(String.valueOf(banhos));
cm= 14.88 * numero * banhos;
if(radio0.isChecked()){
cm = 14.88 * numero * banhos;
}
else if(radio1.isChecked()){
cm = 20.93 * numero * banhos;
}
else if(radio2.isChecked()){
cm = 25.58 * numero * banhos;
}
else if(radio3.isChecked()){
cm = 27.90 * numero * banhos;
}
else if(radio4.isChecked()){
cm = 34.88 * numero * banhos;
}
editText4.setText(String.valueOf(cm));
}
@SuppressWarnings("unused")
public boolean isEletrico() {
return eletrico;
}
public void setEletrico(boolean eletrico) {
this.eletrico = eletrico;
}
});
}
}
Error presented:
06-11 22:47:18.216: E/AndroidRuntime(3738): FATAL EXCEPTION: main
06-11 22:47:18.216: E/AndroidRuntime(3738): Process: com.example.chuveiroappuva, PID: 3738
06-11 22:47:18.216: E/AndroidRuntime(3738): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.chuveiroappuva/com.example.chuveiroappuva.ChuveiroAppUVA}: java.lang.NumberFormatException: Invalid int: ""
06-11 22:47:18.216: E/AndroidRuntime(3738): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
06-11 22:47:18.216: E/AndroidRuntime(3738): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
06-11 22:47:18.216: E/AndroidRuntime(3738): at android.app.ActivityThread.access$800(ActivityThread.java:135)
06-11 22:47:18.216: E/AndroidRuntime(3738): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
06-11 22:47:18.216: E/AndroidRuntime(3738): at android.os.Handler.dispatchMessage(Handler.java:102)
06-11 22:47:18.216: E/AndroidRuntime(3738): at android.os.Looper.loop(Looper.java:136)
06-11 22:47:18.216: E/AndroidRuntime(3738): at android.app.ActivityThread.main(ActivityThread.java:5001)
06-11 22:47:18.216: E/AndroidRuntime(3738): at java.lang.reflect.Method.invokeNative(Native Method)
06-11 22:47:18.216: E/AndroidRuntime(3738): at java.lang.reflect.Method.invoke(Method.java:515)
06-11 22:47:18.216: E/AndroidRuntime(3738): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
06-11 22:47:18.216: E/AndroidRuntime(3738): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
06-11 22:47:18.216: E/AndroidRuntime(3738): at dalvik.system.NativeStart.main(Native Method)
06-11 22:47:18.216: E/AndroidRuntime(3738): Caused by: java.lang.NumberFormatException: Invalid int: ""
06-11 22:47:18.216: E/AndroidRuntime(3738): at java.lang.Integer.invalidInt(Integer.java:137)
06-11 22:47:18.216: E/AndroidRuntime(3738): at java.lang.Integer.parseInt(Integer.java:358)
06-11 22:47:18.216: E/AndroidRuntime(3738): at java.lang.Integer.parseInt(Integer.java:331)
06-11 22:47:18.216: E/AndroidRuntime(3738): at com.example.chuveiroappuva.ChuveiroAppUVA.onCreate(ChuveiroAppUVA.java:54)
06-11 22:47:18.216: E/AndroidRuntime(3738): at android.app.Activity.performCreate(Activity.java:5231)
06-11 22:47:18.216: E/AndroidRuntime(3738): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
06-11 22:47:18.216: E/AndroidRuntime(3738): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
06-11 22:47:18.216: E/AndroidRuntime(3738): ... 11 more
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="ChuveiroAppUVA Por UVA" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="Numero de Pessoas"
android:textAppearance="?android:attr/textAppearanceSmall" />
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:layout_centerHorizontal="true"
android:ems="10"
android:inputType="number" >
android:text="1"/>
<requestFocus />
</EditText>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editText1"
android:layout_centerHorizontal="true"
android:text="Quantidade de Banhos Pessoa"
android:textAppearance="?android:attr/textAppearanceSmall" />
<EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView2"
android:layout_centerHorizontal="true"
android:ems="10"
android:inputType="number" />
android:text="1"/>
<Button
android:id="@+id/button1"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editText2"
android:layout_centerHorizontal="true"
android:text="Calcular" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/button1"
android:layout_centerHorizontal="true"
android:text="Banhos Tomados Diariamente"
android:textAppearance="?android:attr/textAppearanceSmall" />
<EditText
android:id="@+id/editText3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView3"
android:layout_centerHorizontal="true"
android:ems="10"
android:inputType="number" />
android:text="1"/>
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editText3"
android:layout_centerHorizontal="true"
android:text="Eletrico?" />
<Button
android:id="@+id/button2"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/textView4"
android:layout_alignLeft="@+id/button1"
android:layout_marginBottom="16dp"
android:text="Calcular" />
<RadioGroup
android:id="@+id/radioGroup1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/checkBox1" >
<RadioButton
android:id="@+id/radio0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="3200W" />
</RadioGroup>
<RadioButton
android:id="@+id/radio1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/radioGroup1"
android:layout_toRightOf="@+id/radioGroup1"
android:text="4500W" />
<RadioButton
android:id="@+id/radio2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/radio1"
android:layout_alignBottom="@+id/radio1"
android:layout_alignRight="@+id/textView4"
android:text="5500W" />
<RadioButton
android:id="@+id/radio3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/radioGroup1"
android:text="6000W" />
<RadioButton
android:id="@+id/radio4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/textView5"
android:layout_alignParentLeft="true"
android:text="7500W" />
<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/editText4"
android:layout_centerHorizontal="true"
android:layout_marginBottom="27dp"
android:text="Custo Mensal"
android:textAppearance="?android:attr/textAppearanceSmall" />
<EditText
android:id="@+id/editText4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/button2"
android:layout_alignLeft="@+id/editText3"
android:ems="10"
android:inputType="numberDecimal" />
android:text="1"/>
from what I can see from your code, it’s probably because Voce is trying to convert an integer value from an empty edittext, trying to put a default value on it in your Activity.xml declaration, type:
<EditText ... android:inputType="number" android:ems="10" android:text="1" />
if it works let us know, if it doesn’t let us know.– Armando Marques Sobrinho
I just made that continued the same mistake
– Rafael Santiago
put the . xml file of your layout that I test here and put the result
– Armando Marques Sobrinho
Or then, first takes the edittext value in a string
String txt1 = editText1.getText().toString();
and then convert that value to intnumero = Integer.parseInt(text1));
and marks a breakpoint and debug to see the values being passed in your code.– Armando Marques Sobrinho
I’m not managing to make this change has how to help me??
– Rafael Santiago