我不知道我做错了什么,但我有一个名为 input 的编辑文本,用户在其中写一个数字,然后你按下一个按钮:
input = (EditText) findViewById(R.id.input);
XX= (Button) findViewById(R.id.XX);
XX.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
if(XX.equals("XX"))
{
String aa= String.valueOf(input) ;
float operation= ((float) ( 0.029 * 2.2 *aa ) );
String cadena= String.valueOf(operation) ;
// set text to cadena (result of the operation)
predic = (TextView) findViewById(R.id.predic);
predic.setText(cadena);
}
问题是我无法执行此操作
浮动操作=((浮动)(0.029 * 2.2 *aa));
因为它在“aa”下划线并说
"运算符'*'不能应用于'double'、'java.lang.String'"
我想他认为 aa 是一个字符串,我怎样才能让它被读取为一个 Int?
LOGCAT1
09-07 23:18:07.915 10148-10148/com.example.XXXE/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.NumberFormatException: unable to parse 'android.widget.EditText@405a8b98' as integer
at java.lang.Integer.parse(Integer.java:383)
at java.lang.Integer.parseInt(Integer.java:372)
at java.lang.Integer.parseInt(Integer.java:332)
***at com.example.XXX.XXX$5.onClick(XXX.java:542)*** CRASHES
at android.view.View.performClick(View.java:2506)
at android.view.View$PerformClick.run(View.java:9112)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3835)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)
at dalvik.system.NativeStart.main(Native Method)
09-07 23:18:07.965 3698-17447/system_process W/ActivityManager﹕
Force finishing activity com.example.XXXX/.XXXX