• Post Reply Bookmark Topic Watch Topic
  • New Topic

Display Empty String Error in Label  RSS feed

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When testing my program i run into this issue (Empty String) when one or more cells in my weight row are empty when i go to calculate the weight totals. In the program I can keep pressing my "calculate" button and nothing will happen until I enter a value in that column, however, I get this specific error in the console. When a value is entered in that column in each row all my calculations work great.

I have set up a label in my program which handles errors when conditions are met like " No row(s) to update." when you click UPDATE button and there are no rows in the table. Or, if there is a row and its not selected, "Select a row first" when UPDATE button is pressed. This process works great and i'd like to use the same process for this button as well. I'm just not sure how the heck to get there.

Here is what I have in regards to the loop and getting the column value which doesn't seem to catch anything.

 
Sheriff
Posts: 4289
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My thought is this: your error label is probably showing you the last value you put in it. Do you do something else in the loop that puts a value in lMessage?

Even if not, it's a better solution to set a flag in the loop when a value is missing and after the loop, if the flag is set, display the error.
 
Jeff Zak
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I may or may not have an error in the label but it gets cleared before this loop takes effect. I'll read up on that flag stuff
and give that a shot. Thanks for the help.

 
Knute Snortum
Sheriff
Posts: 4289
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The flag can be as simple at a boolean variable:

Then in the loop, set anErrorOcurred to true if the value is null. After the loop, test the boolean:
 
Jeff Zak
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Knute..

I solved my problem but just did it a different way than what you mentioned. What I did was just search for the null or empty value in a single column, then
just put a value in there in its place. In this case, since its a columns called WEIGHT, i just added a "0". So, if the user doesn't put in a value for the weight
it will just automatically give them a 0 in the cell or any other in that column. Here's the code.



Thanks for all the help, anyhow!
 
Sheriff
Posts: 22845
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's a solution, sure, but would it maybe be easier to just initialize everything in that column to zero?
 
Jeff Zak
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's a solution, sure, but would it maybe be easier to just initialize everything in that column to zero?


I could but what would happen if the user enters a new value , say 325 for the weight and updates. Again, the user makes a change and fills out the row with a new part and accidentally leaves the weight entry blank, clicks update, then decides to calculate the weight total. Does that empty cell then revert to 0 again or will it be an empty string?
 
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That depends how you have programmed your app to update that text field. Surely you would not use a label for text entry.
 
Paul Clapham
Sheriff
Posts: 22845
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeff Zak wrote:Does that empty cell then revert to 0 again or will it be an empty string?


What empty cell? If you initialize a column of cells to zero, they stay zero until your code changes them to something else. There's no reverting going on in the Swing code, any reverting which happens is because you did it.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!