User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 391,158 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,243 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 564 | Replies: 2 | Solved
Reply
Join Date: May 2007
Posts: 8
Reputation: Nperic is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Nperic Nperic is offline Offline
Newbie Poster

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

  #1  
Aug 28th, 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.

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("");
        } 
    }
}
AddThis Social Bookmark Button
Reply With Quote  
Join Date: May 2007
Location: USA
Posts: 2,594
Reputation: Ezzaral is just really nice Ezzaral is just really nice Ezzaral is just really nice Ezzaral is just really nice Ezzaral is just really nice 
Rep Power: 11
Solved Threads: 257
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Posting Maven

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

  #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  
Join Date: May 2007
Posts: 8
Reputation: Nperic is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Nperic Nperic is offline Offline
Newbie Poster

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

  #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  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb Java Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the Java Forum

All times are GMT -4. The time now is 7:16 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC