Logic Error? (Need Help, Getting Exception Part II lol)

Thread Solved

Join Date: May 2007
Posts: 14
Reputation: Nperic is an unknown quantity at this point 
Solved Threads: 0
Nperic Nperic is offline Offline
Newbie Poster

Logic Error? (Need Help, Getting Exception Part II lol)

 
0
  #1
Aug 29th, 2007
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.

  1. public void actionPerformed(ActionEvent e){
  2. String command = e.getActionCommand();
  3. if(command.equals("Join Game")){
  4. serverResponseArea.append("Sending join game request\n");
  5. try{
  6. clientHOPP.send(new Message(JOIN_REQUEST));
  7. Message msg = (Message)clientHOPP.receive();
  8. if(msg.getType() == JOIN_ACK){
  9. serverResponseArea.append("Successfully joined game\n");
  10. activeGame = true;
  11. joinButton.setEnabled(false);
  12. }
  13. } catch (IOException e1) {
  14. serverResponseArea.append("Communication Error: "+e1.getMessage());
  15. } catch (ClassNotFoundException cnf) {
  16. serverResponseArea.append(cnf.getMessage());
  17. }
  18. }
  19. else if(command.equals("Submit Guess")){
  20. String inString = guessField.getText().trim();
  21. if(inString == null || inString.length() == 0){
  22. serverResponseArea.append("Please enter a number \n");
  23. }
  24. int input = Integer.parseInt(inString);
  25. serverResponseArea.append("Guess is: " + inString +"\n");
  26. try{
  27. clientHOPP.send(new Message(input));
  28. /*Test*/serverResponseArea.append(input+" sent.\n");
  29. guessField.setText("");
  30. Message inMsg = (Message)clientHOPP.receive();
  31. if(inMsg.getType()== GUESS_RESPONSE)
  32. {
  33. GuessResponse response = (GuessResponse)inMsg.getMessageContents();
  34. if(response.getResponseType()==HIGHER)
  35. serverResponseArea.append("(Guess # "+response.getGuessNumber()+"): HIGHER!");
  36. else if(response.getResponseType() == LOWER)
  37. serverResponseArea.append("(Guess # "+response.getGuessNumber()+"): LOWER!");
  38. else if(response.getResponseType() == INVALID_NUMBER)
  39. serverResponseArea.append("Invalid number. Please choose a number between 1 - 999");
  40. else if(response.getResponseType() == WIN)
  41. serverResponseArea.append("Congratulations. You Win in "+response.getGuessNumber()+" guesses");
  42. else if(response.getResponseType() == LOSE)
  43. serverResponseArea.append("Sorry, you lose");
  44. }
  45. } catch (IOException e1) {
  46. // TODO Auto-generated catch block
  47. e1.printStackTrace();
  48. } catch(ClassNotFoundException cnf){
  49. serverResponseArea.append(cnf.getMessage());
  50. }
  51. serverResponseArea.append(inString+"\n");
  52. guessField.setText("");
  53. }
  54. }
  55. }
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,438
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 510
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: Logic Error? (Need Help, Getting Exception Part II lol)

 
0
  #2
Aug 29th, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 14
Reputation: Nperic is an unknown quantity at this point 
Solved Threads: 0
Nperic Nperic is offline Offline
Newbie Poster

Re: Logic Error? (Need Help, Getting Exception Part II lol)

 
0
  #3
Aug 31st, 2007
Yeah i did some debugging. I was getting a null because my streams werent initialised in the right order. Thanks for the tip
I love the support on this forum.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC