hi
i want to create a simple android app that gets two numbers in the main activity and when we click submit it goes to another activity and displays the result.
i created two classes
mainactivity.java
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
EditText et1=(EditText) findViewById(R.id.editText1);
EditText et2=(EditText) findViewById(R.id.editText2);
Button b=(Button) findViewById(R.id.button1);
final int result=Integer.parseInt(et1)+Integer.parseInt(et2);
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent=new Intent(MainActivity.this,Result.class);
intent.putExtra("Result", result);
startActivity(intent);
}
});
}
Result.java
public class Result extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_result);
TextView tv=(TextView) findViewById(R.id.textView1);
tv.setText(getIntent().getExtras().getInt("Result"));
}
i am getting error. the apps asks to force close. please help me