Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Unable to populate String

 
Patrick Boos
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 106
Mac Mac OS X Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!

 
fred rosenberger
lowercase baba
Bartender
Posts: 12198
35
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Patrick Boos
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 12198
35
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 106
Mac Mac OS X Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so its working?

good work
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic