0
I’m creating an application but in case it gives problem when running to a certain point, I want to transform geoi = 0; and Mati = 0; , and when I add any number in edittext it will put that number inside the geoi and Mati int which in the case is equal to 0. What is the error in my code ? Why are you giving Unfortunately ?
package com.gustavo.sample;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends ActionBarActivity {
CheckBox g;
CheckBox m;
Button send;
TextView say;
EditText num;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
bacon();
send.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String counter = num.getText().toString();
int counterAsInt = Integer.parseInt(counter);
int geoi = 0;
int mati = 0;
if(g.isChecked()){
geoi += counterAsInt;
say.setText("Geo" + geoi);
}
else if(m.isChecked()){
mati += counterAsInt;
say.setText("Math" + mati);
}
}
});
}
public void bacon() {
g = (CheckBox)findViewById(R.id.checkBox1);
m = (CheckBox)findViewById(R.id.checkBox2);
send = (Button)findViewById(R.id.button1);
say = (TextView)findViewById(R.id.textView1);
num = (EditText)findViewById(R.id.editText1);
}
}
Gustavo, you need to include the
stacktrace
error that appears in your logIDE
. Without this you can not guess which error occurred in your code, because at first there is no.– Wakim
@Gustavo Dibai tries to make his class inherit from Activity.. public class Mainactivity extends Activity.. another say and check the names in findViewById to see if it is not wrong id
– Pedro Rangel
Actionbaractivity has the same methods of Activity but some complementary.
– Dibai
Wakim I’ll try that vlw
– Dibai
@Wakim could you help me do the stacktrace ? Inside my code ?
– Dibai
Look at the Logcat from the IDE, you need to be plugged into the USB and running the ADB.
– Wakim
Androidruntime at java.lang.Integer.parseint(Integer.java:366)
– Dibai
Copy the
stacktrace
whole, it has dozens of lines, in his question for better visualization.– Wakim
@Gustavodibai, the
stacktrace
is already being shown, but need to check in yourIDE
, which one you’re wearing?– Wakim
@Wakim Aee I think I found 09-29 20:07:22.892: E/androidruntime(1437): FATAL EXCEPTION: main 09-29 20:07:22.892: E/Androidruntime(1437): java.lang.Numberformatexception: Invalid int: "1.5" 09-29 20:07:22.892: E/Androidruntime(1437): at java.lang.Integer.invalidInt(Integer.java:138) 09-29 20:07:22.892: E/Androidruntime(1437): at java.lang.Integer.parse(Integer.java:375) 09-29 20:07:22.892: E/Androidruntime(1437): at java.lang.Integer.parseint(Integer.java:366) 09-29 20:07:22.892: E/Androidruntime(1437): at java.lang.Integer.parseint(Integer.java:332)
– Dibai
@Wakim think I’ve got the bug, I’m putting decimals, and it’s only integer numbers over and now what I’ve done to run the decimals too ?
– Dibai