473,473 Members | 1,978 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How can I convert a JTextField that's returning null to a different string value?

9 New Member
I have a JTextField that I'm not always passing a value to, but it causes an exception to be thrown when the program runs if the person hasn't entered anything into the JTextField. I have some code below that I'm trying to convert a null response into a different String value. Why isn't it assigning stringInput as a String of "0"?

Expand|Select|Wrap|Line Numbers
  1.             String stringInput = " ";
  2.             stringInput = dinnerTextField.getText();
  3.             if (stringInput == null)
  4.                stringInput = "0";
  5.  
Mar 5 '12 #1
1 1657
r035198x
13,262 MVP
Maybe stringInput is the empty string "" rather than null.
To handle that you could use

Expand|Select|Wrap|Line Numbers
  1. if(stringInput == null || stringInput.trim().equals("")) {
Mar 5 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Jamie Burns | last post by:
Hello, I am trying to perform a LEFT JOIN on a table which may or may not have matching rows. If there are no matching rows, it returns NULL's for all the missing fields. Is there anyway of...
1
by: faktujaa | last post by:
Hi, I have date in a string format like string strDate = "110204". Now i want to convert this string to MM/dd/yyyy format. How do i do this???? I used string.Format(strDate, "MM/dd/yyyy") but no...
0
by: George Durzi | last post by:
cross posted in datagrid group. Inside <columns/> in my datagrid, I have the following template column <asp:templatecolumn HeaderText="To Be Completed By"> <itemtemplate> <asp:Label...
0
by: Toska | last post by:
Hi, Wonder how I can convert a string value to enum value. Code ------------------- <appSettings> <add key="BaseType" value="Sand" /> </appSettings>
9
by: Thomas Mlynarczyk | last post by:
Hi, It seems to be a generally adopted convention to have a function return FALSE in case of an error. But if a function is supposed to return a boolean anyway, one cannot distinguish anymore...
28
by: Andre | last post by:
Hi, Does anyone know whether the ECMA, or an other standard document, specifies a maximum for the value that can be pass to the setTimeOut() function in Javascript? Andre
4
by: Java Apache | last post by:
Hi All, I am pretty to new to .NET/C# so go easy! I am developing a Web Service call to a Java Web Service and it is all working fine - it is returning me back a String value which in all...
5
by: Wilfried Mestdagh | last post by:
Hi, I have a DLL using stdcall and a function of it is returning a null terminated string. How do I declare this in C# (VS2005) ? I try things like: public static extern string...
17
by: mac | last post by:
Hi, I'm trying to write a fibonacci recursive function that will return the fibonacci string separated by comma. The problem sounds like this: ------------- Write a recursive function that...
1
by: sbowman | last post by:
I have the following CASE statement in a view: (SELECT CASE WHEN ISNULL(.., NULL) = NULL THEN .(..) ELSE .(..) + ', ' + .. END) AS ContactNameAndTitle It works perfectly when...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.