Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/197.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 无法将EditText文本转换为int 我试图制作一个简单的高尔夫得分应用程序,当我试图转换编辑文本中的数字时,我遇到了一个问题。用户只能在编辑文本中输入数字。当我运行它时,它不会显示任何错误,也不会崩溃,但无论EditText中有什么内容,它显然不会从下面的代码中获取值。如果我将PAR设置为0以外的数字,它将影响用户进入下一个孔时的总得分,从而使部分代码工作。此外,当我将此代码移动到onClick(View v)以外的其他方法时,应用程序崩溃。感谢所有的帮助 public void onClick(View v){ if (parNum.getText().toString().equals("")){ AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.setTitle("Please enter the par"); alert.show(); } else { //editvalue is a string that I declared but gave no value. editvalue = parNum.getText().toString(); par = Integer.parseInt(editvalue); } }_Android - Fatal编程技术网

Android 无法将EditText文本转换为int 我试图制作一个简单的高尔夫得分应用程序,当我试图转换编辑文本中的数字时,我遇到了一个问题。用户只能在编辑文本中输入数字。当我运行它时,它不会显示任何错误,也不会崩溃,但无论EditText中有什么内容,它显然不会从下面的代码中获取值。如果我将PAR设置为0以外的数字,它将影响用户进入下一个孔时的总得分,从而使部分代码工作。此外,当我将此代码移动到onClick(View v)以外的其他方法时,应用程序崩溃。感谢所有的帮助 public void onClick(View v){ if (parNum.getText().toString().equals("")){ AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.setTitle("Please enter the par"); alert.show(); } else { //editvalue is a string that I declared but gave no value. editvalue = parNum.getText().toString(); par = Integer.parseInt(editvalue); } }

Android 无法将EditText文本转换为int 我试图制作一个简单的高尔夫得分应用程序,当我试图转换编辑文本中的数字时,我遇到了一个问题。用户只能在编辑文本中输入数字。当我运行它时,它不会显示任何错误,也不会崩溃,但无论EditText中有什么内容,它显然不会从下面的代码中获取值。如果我将PAR设置为0以外的数字,它将影响用户进入下一个孔时的总得分,从而使部分代码工作。此外,当我将此代码移动到onClick(View v)以外的其他方法时,应用程序崩溃。感谢所有的帮助 public void onClick(View v){ if (parNum.getText().toString().equals("")){ AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.setTitle("Please enter the par"); alert.show(); } else { //editvalue is a string that I declared but gave no value. editvalue = parNum.getText().toString(); par = Integer.parseInt(editvalue); } },android,Android,您正在检查不等于“”。所以请删除符号 if (parNum.getText().toString().equals("")){ AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.setTitle("Please enter the par"); alert.show(); } else { //editvalue is a string that I declared but gave

您正在检查
不等于“”
。所以请删除
符号

if (parNum.getText().toString().equals("")){
    AlertDialog.Builder alert = new AlertDialog.Builder(this);
    alert.setTitle("Please enter the par");
    alert.show();
}
else {
    //editvalue is a string that I declared but gave no value.
    editvalue = parNum.getText().toString(); 
    par = Integer.parseInt(editvalue);
}

<>我希望这能对你有所帮助。

这没什么区别,警报根本没有显示出来。没有任何PAR停留在0,警报也没有显示出来,因为你在初始化你的代码> PARNUM < /代码>。在OnCube中,我做了一个编辑文本。你可以分享你在Edittext写的是什么价值吗?…我不太清楚你的意思。EditText为空,用户只能在其中输入数字0123456789。您将此代码放在btn click或..上的位置?它位于onClick(视图v)方法上,因此当用户单击视图时,此代码将运行。