尝试从EditText获取double值并在将它们传递给另一个Intent之前对其进行操作.不使用原始数据类型,所以我可以使用toString方法.
问题是当我包含蛋白质= Double.valueOf(p).doubleValue(); 样式命令,程序强制立即关闭而不在logcat中留下任何信息.如果我将它们注释掉并设置一些虚拟数据,如protein = 1.0; 它没有任何问题.原始数据类型和解析double也是如此.此代码与普通java中的虚拟数据完美配合.我究竟做错了什么?
EditText txtProt, txtCarb, txtFat, txtFiber, txtPoints;
String p, c, f, fi;
Double protein, carbs, fat, fiber;
double temp;
Integer points;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.v("Create Prompt", "ready for layout");
setContentView(R.layout.main);
Log.v("Layout Created", "ready for variable assignment");
txtProt = (EditText) findViewById(R.id.Protein);
txtCarb = (EditText) findViewById(R.id.Carbs);
txtFat = (EditText) findViewById(R.id.Fat);
txtFiber = (EditText) findViewById(R.id.Fiber);
txtPoints = (EditText) findViewById(R.id.Points);
btnCalc = (Button) findViewById(R.id.Calc);
Log.v("Variables Assigned", "ready for double assignment");
p = txtProt.getText().toString();
c …Run Code Online (Sandbox Code Playgroud)