当我尝试将编辑文本值分配为浮动时,我的应用程序强制关闭。这是代码。我还尝试了 Float.parseFloat() 方法而不是 Float.valueOf()。如果我取消我的 getETvalue() 方法,那么应用程序就可以工作。请帮忙
package com.example.aviator_18;
import android.os.Bundle;
import android.app.Activity;
import android.graphics.Color;
import android.view.Menu;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity {
float Remaining,Departure,TotUplift,SG,DiscResult;
int CalUpliftResult;
TextView RemainingTV,DepartureTV,UpliftTV,SGtv,CalcUpliftTV,DiscrepancyTV;
EditText RemainingET,DepartureET,TotUpliftET,SGet,CalcUpliftET,DiscrepancyET;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setupView();
getETvalue();
evaluation();
CalcUpliftTV.setText(String.valueOf(CalUpliftResult));
DiscrepancyTV.setText(String.valueOf(DiscResult));
}
private void getETvalue() {
String a,b,c,d,e;
Remaining=Float.valueOf(RemainingET.getText().toString());
Departure=Float.valueOf(DepartureET.getText().toString());
TotUplift=Float.valueOf(TotUpliftET.getText().toString());
SG=Float.valueOf(SGet.getText().toString());
}
private void evaluation() {
CalUpliftResult=Math.round(TotUplift*SG);
DiscResult=((Departure-Remaining-CalUpliftResult)/CalUpliftResult)*100;
}
private void setupView() {
RemainingET=(EditText)findViewById(R.id.remainingET);
DepartureET=(EditText)findViewById(R.id.departureET);
TotUpliftET=(EditText)findViewById(R.id.TotalUpliftET);
SGet=(EditText)findViewById(R.id.SGet);
CalcUpliftTV=(TextView)findViewById(R.id.CalUpliftResult);
DiscrepancyTV=(TextView)findViewById(R.id.discResult);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}