473,586 Members | 2,566 Online
Bytes | Software Development & Data Engineering Community
+ 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 1666
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
14648
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 returning the default values for that table instead of NULL's, in a portable way?
1
320
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 effect. I guess i have to convert this to date and than to string(MM/dd/yyyy). Please help. Thanks in advance. faktujaa
0
2189
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 runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.FULL_NAME") %>'><asp:label> </itemtemplate> <edititemtemplate>
0
1365
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
5191
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 between the "normal" FALSE and the "error" FALSE. So why not using NULL instead to indicate an error? Are there drawbacks I am not aware of? ...
28
5272
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
30569
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 reality is an XML file (the content of the string is a valid well-formed XML packet). How can I get this string into an XML object so I can use the...
5
3035
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 Version();
17
2812
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 creates a character string containing the first n Fibonacci numbers - F(n) = F(n - 1) + F(n - 2), F(0) = F(1) = 1 -, separated by comma. n should be...
1
7464
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 dbo.tblContact.JobTitleID is NOT null. When it
0
7839
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8338
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7959
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8216
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6614
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5710
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3837
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2345
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 we have to send another system
1
1449
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.