点击确定按钮出现一下
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 0
at Client$4.actionPerformed(Client.java:223)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6038)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3260)
at java.awt.Component.processEvent(Component.java:5803)
at java.awt.Container.processEvent(Container.java:2058)
at java.awt.Component.dispatchEventImpl(Component.java:4410)
at java.awt.Container.dispatchEventImpl(Container.java:2116)
at java.awt.Component.dispatchEvent(Component.java:4240)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3986)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916)
at java.awt.Container.dispatchEventImpl(Container.java:2102)
at java.awt.Window.dispatchEventImpl(Window.java:2429)
at java.awt.Component.dispatchEvent(Component.java:4240)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)
错误,
这是为什么呢?lz肯定是 取数组的索引的时候超出范围了因为不太清楚楼主的逻辑,参考一下:
int a = 0;
while((ss = bufferedreader.readLine()) != null) //注意这改了.
{
String[] sss = ss.split(" ");
// ----------------------这加一判断。
if(sss.length==0)
{
continue;
}
//-----------------------
a = compare(sss[0],s1);
if(s2.equals(s4))
{
if(a == 1)
{
JOptionPane.showMessageDialog(f2,"该名已被使用");
break;
}
//ss = bufferedreader.readLine();//这句不要了。
if(a == 0)
{
printwrite.println(s3);
JOptionPane.showMessageDialog(f2, "恭喜你 ,注册成功");数组越界!
看看 Client.java:223 代码.
代码里只有一个数组,sss,对数组的引用只有 sss[0], 报数组越界,说明sss的长度是0,(一个元素都没有)。
楼主可以把从文件里读出的字符串 ss 输出到控制台,把sss的长度输出到控制台看看。
++数组下标越界了,
把Client类 尤其223行 贴出来