【发布时间】:2015-04-16 14:23:58
【问题描述】:
我正在检查用户输入以控制空白输入。像这样在全局类上声明字符串数组,
public static String[] sortAnswer;
但应用程序在 for 循环行开始时在此代码上爆炸。它已在 for 语句上停止。for(int i=0; (i < Global.sortAnswer.length );i++) 当我添加像 .length() 这样带有红色标记的括号时。我确定应该是.length
我主要有两个问题
1-) 初始化字符串数组是错误的?
2-) Global.sortAnswer.length 无法计算数组长度?
btnQuestionSortSend.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
edSortQuestion.setText(Global.firstLetterUpper(edSortQuestion.getText().toString()));
boolean sortCntrol=false;
for(int i=0; (i < Global.sortAnswer.length );i++)
{
if (Global.sortAnswer[i].toString().equals("")||Global.sortAnswer[i].toString()==""||Global.sortAnswer[i].toString().equalsIgnoreCase(""))
{
sortCntrol=true;
}
}
if(edSortQuestion.getText().toString().equals(""))
{
showMessage(con, getResources().getString(R.string.QuestionSort_fillQuestion), -140,"yellow");
}
else if(sortCntrol)
{
showMessage(con, getResources().getString(R.string.Question_Empty), -140,"yellow");
}
谢谢你, 真诚的
【问题讨论】:
-
but application explodes不能很好地描述问题。请提供尽可能多的有关问题所在的详细信息,特别是如果您没有共享错误/异常/堆栈跟踪。另外,您确定应该length而不是length()?这是一种方法,而不是属性。 -
请提供您的异常和堆栈跟踪
-
您的问题在哪里?
-
它已停止在 for 语句上。 for(int i=0; (i
-
当我添加像
.length()这样带有红色标记的括号时。我确定应该是.length
标签: java android arrays for-loop