aspose file tools*
The moose likes Java in General and the fly likes Unable to populate String Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Unable to populate String" Watch "Unable to populate String" New topic
Author

Unable to populate String

Patrick Boos
Greenhorn

Joined: Sep 09, 2008
Posts: 15
Hello,

I am creating a client/server application that verifies math equations for addition, subtraction, and division. I think I just need someone else’s eyes to possibly see where I am going wrong with this. Everything seems to be working fine except for one variable. This is the String serverAnswer variable in my Server class. When I debug the application, the serverAnswer variable remains null, can anyone tell me what I’m doing wrong? I wrote the code for where it should be populated in the processConnection() method of my server class. I know this is a lot of code, but it is needed to debug the application. Thank you.







Lucas Franceschi
Ranch Hand

Joined: Nov 10, 2008
Posts: 106

hello there, welcome!

so, I couldn't figure out what's the problem in your code,
but you seem a lot stressed with this code, try taking a rest, sleep a little, then you look to the code again...

its kind of a mind thing, when you spend too much time in a problem, your mind gets conditionated to look for one specific type of problem, so that you cant see the problem that in some cases can be only some simple logic error, that's right in front of your eyes, but as your mind is tired, you dont note it...

take a free time, rest your mind a bit, then return to this...

still, i expect someone to understand your code and help, some expert javarancher will show up in minutes and will do it.

sorry for the not-helpful-at-all reply, just think it would be nice to say

good luck there Patrick!



Lucas Franceschi
Software Developer for SGI Sistemas, lukas1596@gmail.com
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11246
    
  16

The only place i see the variable "serverAnswer" is here:



serverAnswer is not declared anywhere I see in this code.

So, assuming it is legally declared somewhere, i'd still focus in on this block. It's quite clear that there are ways to drop through this if statement and never assign anything to the variable. put in some extra println() statements and see if you can figure out what's happening here.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Patrick Boos
Greenhorn

Joined: Sep 09, 2008
Posts: 15
Lucas,

Thanks for looking at my code and your advice. I also find that getting away from it can be a good way to get a solution. Take care.

Patrick
Patrick Boos
Greenhorn

Joined: Sep 09, 2008
Posts: 15

Fred,

Thank you for looking at my code. I declared that variable in the Server class right here:



I’m wondering if it is a logic error or something. I have been debugging the program with NetBeans 6.5 and the serverAnswer variable does not populate at any point in the program. I think I’m just going to have to rethink my approach. Thank you for your suggestion.

Patrick
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11246
    
  16

i swear i did a search for it...

but in any case, if you are not assigning anything to it, you're either

a) not entering the do-while loop
b) you enter the try, but an exception is thrown before you assign it
c) you never hit any of the 'if' conditions that assign a value to it.

Seriously, do something like this:



etc.

Then look at your output and you can see exactly what gets executed. or if you're using a debugger, what happens when you get to this loop? set a break point and step through it line by line to see what happens.
Patrick Boos
Greenhorn

Joined: Sep 09, 2008
Posts: 15
Thank you both for your help. I just had to add a little bit of code to processConnection() to get it to work. Here it is:

Lucas Franceschi
Ranch Hand

Joined: Nov 10, 2008
Posts: 106

so its working?

good work
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Unable to populate String