944,204 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Marked Solved
  • Views: 1453
  • Java RSS
Aug 29th, 2007
0

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

Expand Post »
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)
  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. }
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Nperic is offline Offline
14 posts
since May 2007
Aug 29th, 2007
0

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

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.
Moderator
Featured Poster
Reputation Points: 3239
Solved Threads: 839
Posting Genius
Ezzaral is offline Offline
6,761 posts
since May 2007
Aug 31st, 2007
0

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

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Nperic is offline Offline
14 posts
since May 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Dynamic Loading
Next Thread in Java Forum Timeline: is it possible to link a java file?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC