I'm a newbie to android developing from Sri Lanka.
I coded for a simple calculator, the code is error free (shown in
eclipse IDE) and while the code starts to run the console window of
eclipse IDE is not giving any error. After the emulator starts, I got
"Sorry! Application Hello Android (process com.helloAndroid)has
stopped unexpectedly please try again".
After I click the "Force close"button the app stops work. I don't have
any android phone to run that and I used only emulator.
My code is :
++++++++++++++++++++++++++++++++++++++++++++++++
package com.helloAndroid;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import java.math.*;
public class HelloAndroid extends Activity {
/** Called when the activity is first created. */
private EditText editText=null;
private Button btnOne = null;
private Button btnTwo = (Button) findViewById(R.id.btnTwo);
private Button btnThree = (Button) findViewById(R.id.btnThree);
private Button btnFour = (Button)findViewById(R.id.btnFour);
private Button btnFive = (Button) findViewById(R.id.btnFive);
private Button btnSix = (Button) findViewById(R.id.btnSix);
private Button btnSeven = (Button) findViewById(R.id.btnSeven);
private Button btnEight = (Button) findViewById(R.id.btnEight);
private Button btnNine = (Button) findViewById(R.id.btnNine);
private Button btnZero = (Button) findViewById(R.id.btnZero);
private Button btnAdd = (Button) findViewById(R.id.btnAdd);
private Button btnSubstract = (Button)
findViewById(R.id.btnSubstract);
private Button btnMultiply = (Button) findViewById(R.id.btnMultiply);
private Button btnSin = (Button) findViewById(R.id.btnSin);
private Button btnCos = (Button) findViewById(R.id.btnCos);
private Button btnTan = (Button) findViewById(R.id.btnTan);
private Button btnPi = (Button) findViewById(R.id.btnPi);
private Button btnSqrt = (Button) findViewById(R.id.btnSqrt);
private Button btnSquare = (Button) findViewById(R.id.btnSquare);
private Button btnEqual = (Button) findViewById(R.id.btnEqual);
private String text= editText.getText().toString();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btnOne.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
text=text+"1";
editText.setText(text);
}
});
btnTwo.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
text=text+"2";
editText.setText(text);
}
});
btnThree.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
text=text+"3";
editText.setText(text);
}
});
btnFour.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
text=text+"4";
editText.setText(text);
}
});
btnFive.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
text=text+"5";
editText.setText(text);
}
});
btnSix.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
text=text+"6";
editText.setText(text);
}
});
btnSeven.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
text=text+"7";
editText.setText(text);
}
});
btnEight.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
text=text+"8";
editText.setText(text);
}
});
btnNine.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
text=text+"9";
editText.setText(text);
}
});
btnZero.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
text=text+"0";
editText.setText(text);
}
});
btnSin.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Double Val=Math.sin(Double.parseDouble(text));
editText.setText(Val.toString());
}
});
btnCos.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Double Val=Math.cos(Double.parseDouble(text));
editText.setText(Val.toString());
}
});
btnTan.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Double Val=Math.tan(Double.parseDouble(text));
editText.setText(Val.toString());
}
});
btnSqrt.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Double Val=Math.sqrt(Double.parseDouble(text));
editText.setText(Val.toString());
}
});
btnSquare.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Double
Val=Double.parseDouble(text)*Double.parseDouble(text);
editText.setText(Val.toString());
}
});
btnPi.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Double Val=(double) (22/7);
editText.setText(Val.toString());
}
});
}
}
+++++++++++++++++++++++++++++++++++++++++++++++++++
I'm running a Intel Celeron 1.8GHz, 1GB memory computer with Win7.
I target the device for Android 2.1 - API level 7 and didn't set SD
card...
please help me
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en