PDA

View Full Version : need help from a java programmer



99shassan
04-04-2008, 10:18 AM
I have a gui and I did something to it last night, and now it won't send numbers to a server.

I have 6 text boxes, I save the number in those boxes in an array. Then set up a loop that sends each number to an already connected client. However, when I get to the last number, the server keeps stopping and giving me this error:

java.lang.ArrayIndexOutOfBoundsException: -3
at JavaServer.lottery(JavaServer.java:215)
at JavaServer.main(JavaServer.java:249)
java.lang.NullPointerException
at JavaServer.main(JavaServer.java:255)

:angry:

I have no idea why. since both arrays are 6.

using scanner as input on both client and server
server

input


scanner ClientIn = new Scanner
(connection.getInputStream());

output:
Prin***iter Output = new Prin***iter(connection.getOutputStream(), true);
client


Scanner input = new Scanner(clconn.getInputStream());

//output so client can send to server
Prin***iter output = new Prin***iter
(clconn.getOutputStream(),true);
and on my client, the error message i get is




java.util.NoSuchElementException: No line found
at java.util.Scanner.nextLine(Scanner.java:1516)
at Main.SendNumberstoServerButtonActionPerformed(Main.java:863)
at Main.access$500(Main.java:17)
at Main$6.actionPerformed(Main.java:231)
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:6041)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)
at java.awt.Component.processEvent(Component.java:5806)
at java.awt.Container.processEvent(Container.java:2058)
at java.awt.Component.dispatchEventImpl(Component.java:4413)
at java.awt.Container.dispatchEventImpl(Container.java:2116)
at java.awt.Component.dispatchEvent(Component.java:4243)
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:2440)
at java.awt.Component.dispatchEvent(Component.java:4243)
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)


where I think its referring to is here:

server


if (status==1){
Thread.sleep(900);
System.out.println("waitfail");
ServerOutput.println("NO");
}
else {
Thread.sleep(900);
System.out.println("waitpass");
ServerOutput.println("OK");
index=2;
}
client



status = input.nextLine();


On further inspection, it seems that the server receives the 6 numbers just fine (I have a println command to print out the numbers it receives, which it does. But when it gets to that point, that happens.

99shassan
04-07-2008, 06:35 PM
solved it, I declared a socket twice

WarrenBuffet
04-11-2008, 03:52 PM
u sux lolz