这个错怎么解决,跪求大神 5
btnNewButton.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEv...
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
int a=0;
String arrayStr;
arrayStr = textField.getText().trim();
for(int i=0;i<arrayStr.length();i++)
{
char charAt = arrayStr.charAt(i);
char charAt1 = arrayStr.charAt(i+1);
if(charAt==' '&&charAt1!=' ')
{
a++;
}
if(!Character.isDigit(charAt)&&charAt!=' ')
{
JOptionPane.showMessageDialog(null,"输入包含非法字符");
textField.setText("");
return;
}
}
String[] numStrs =new String[a];
numStrs = arrayStr.split("{1,}");
//textField1.setText(numStrs[0]);
//lblNewLabel.setText(numStrs[0]);
int[] numArray = new int[numStrs.length];
for(int i=0;i<numArray.length;i++)
{
numArray[i] = Integer.valueOf(numStrs[i]);
}
int min = numArray[0];
for(int j=0;j<numArray.length;j++)
{
if(min>numArray[j])
{
min=numArray[j];
}
}
textField1.setText(String.valueOf(min));
}
}
出现以下错误
Exception in thread "AWT-EventQueue-0" java.lang.StringIndexOutOfBoundsException: String index out of range: 5
at java.lang.String.charAt(Unknown Source)
at designer.ArrayMinValue$2.actionPerformed(ArrayMinValue.java:63)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
。。。。。 展开
public void actionPerformed(ActionEvent arg0) {
int a=0;
String arrayStr;
arrayStr = textField.getText().trim();
for(int i=0;i<arrayStr.length();i++)
{
char charAt = arrayStr.charAt(i);
char charAt1 = arrayStr.charAt(i+1);
if(charAt==' '&&charAt1!=' ')
{
a++;
}
if(!Character.isDigit(charAt)&&charAt!=' ')
{
JOptionPane.showMessageDialog(null,"输入包含非法字符");
textField.setText("");
return;
}
}
String[] numStrs =new String[a];
numStrs = arrayStr.split("{1,}");
//textField1.setText(numStrs[0]);
//lblNewLabel.setText(numStrs[0]);
int[] numArray = new int[numStrs.length];
for(int i=0;i<numArray.length;i++)
{
numArray[i] = Integer.valueOf(numStrs[i]);
}
int min = numArray[0];
for(int j=0;j<numArray.length;j++)
{
if(min>numArray[j])
{
min=numArray[j];
}
}
textField1.setText(String.valueOf(min));
}
}
出现以下错误
Exception in thread "AWT-EventQueue-0" java.lang.StringIndexOutOfBoundsException: String index out of range: 5
at java.lang.String.charAt(Unknown Source)
at designer.ArrayMinValue$2.actionPerformed(ArrayMinValue.java:63)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
。。。。。 展开
1个回答
亚远景信息科技
2024-12-11 广告
2024-12-11 广告
ASPICE,全称Automotive SPICE,中文译为汽车软件过程改进及能力评定,是评估和改进汽车软件开发流程的国际标准。它旨在提高软件开发的质量和效率,确保软件符合质量要求及安全、法规标准。ASPICE基于过程能力和过程改进两大核心...
点击进入详情页
本回答由亚远景信息科技提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询