| | |
Logic Error? (Need Help, Getting Exception Part II lol)
Thread Solved |
•
•
Join Date: May 2007
Posts: 14
Reputation:
Solved Threads: 0
Now i created a Client for the HOPP. i made a button which submits the guess to the server, but logically this doesnt output. What do you think seems to be the problem here.
Java Syntax (Toggle Plain Text)
public void actionPerformed(ActionEvent e){ String command = e.getActionCommand(); if(command.equals("Join Game")){ serverResponseArea.append("Sending join game request\n"); try{ clientHOPP.send(new Message(JOIN_REQUEST)); Message msg = (Message)clientHOPP.receive(); if(msg.getType() == JOIN_ACK){ serverResponseArea.append("Successfully joined game\n"); activeGame = true; joinButton.setEnabled(false); } } catch (IOException e1) { serverResponseArea.append("Communication Error: "+e1.getMessage()); } catch (ClassNotFoundException cnf) { serverResponseArea.append(cnf.getMessage()); } } else if(command.equals("Submit Guess")){ String inString = guessField.getText().trim(); if(inString == null || inString.length() == 0){ serverResponseArea.append("Please enter a number \n"); } int input = Integer.parseInt(inString); serverResponseArea.append("Guess is: " + inString +"\n"); try{ clientHOPP.send(new Message(input)); /*Test*/serverResponseArea.append(input+" sent.\n"); guessField.setText(""); Message inMsg = (Message)clientHOPP.receive(); if(inMsg.getType()== GUESS_RESPONSE) { GuessResponse response = (GuessResponse)inMsg.getMessageContents(); if(response.getResponseType()==HIGHER) serverResponseArea.append("(Guess # "+response.getGuessNumber()+"): HIGHER!"); else if(response.getResponseType() == LOWER) serverResponseArea.append("(Guess # "+response.getGuessNumber()+"): LOWER!"); else if(response.getResponseType() == INVALID_NUMBER) serverResponseArea.append("Invalid number. Please choose a number between 1 - 999"); else if(response.getResponseType() == WIN) serverResponseArea.append("Congratulations. You Win in "+response.getGuessNumber()+" guesses"); else if(response.getResponseType() == LOSE) serverResponseArea.append("Sorry, you lose"); } } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch(ClassNotFoundException cnf){ serverResponseArea.append(cnf.getMessage()); } serverResponseArea.append(inString+"\n"); guessField.setText(""); } } }
This will not be very easy to debug with just the code you posted, as there are several interacting classes here. If you do not have an IDE that will let you step through the code as it executes, then you will need to place assertions or System.out.println() statements at the various stages to verify what is being received and processed on the client and server side. I would recommend starting with testing what response the client is receiving. If that result is not correct then check how the server is processing the input. Good luck!
If you are getting specific exceptions or odd behavior you don't understand, post them back here and perhaps we can help.
If you are getting specific exceptions or odd behavior you don't understand, post them back here and perhaps we can help.
![]() |
Similar Threads
- Exception in thread "main" java.lang.NoClassDefFoundError: Invaders Error (Java)
- Error in exception(RMI) (Java)
- Logic error? (C++)
- Erm, logic error?! (C++)
- Error/Exception handling help (Python)
- Could someone please help me with this logic error?? (VB.NET)
- Program Compiles fine, but error upon Running (Java)
- TCPIP.sys **STOP** Error! HELP! (Windows NT / 2000 / XP)
Other Threads in the Java Forum
- Previous Thread: Dynamic Loading
- Next Thread: how to use switch statement in java on strings
| Thread Tools | Search this Thread |
2dgraphics account android api apple applet application array arrays automation banking bidirectional binary binarytree birt bluetooth chat chatprogramusingobjects class client code columns component database derby design eclipse encryption error errors expand fractal game givemetehcodez graphics gui guidancer homework html ide if_statement image inheritance integer intellij interface j2me java javadesktopapplications javaprojects jlabel jme jni jpanel jtextfield julia linux list map method methods midlethttpconnection mobile mobiledevelopmentcreatejar monitoring myaggfun netbeans newbie nullpointerexception open-source problem program programming project property recursion reference ria scanner search server set sms sort sourcelabs splash sql sqlite static stop string support swing testautomation threads tree ui unicode validation windows






