Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-31-2008, 04:32 PM
Member
 
Join Date: Jul 2008
Posts: 2
vinikz is on a distinguished road
String to Integer Conversion in JSP
Hi,
I have a string. Iam trying to convert this to integer. But iam getting error message. Here iam displaying my code:
<%
int count;
String num=request.getParameter("numFields"); // this value coming from my textbox
out.println("num : "+num);
count = Integer.parseInt(num); // In this line error coming
out.println("Count : "+count);
//for (int x=0; x<count; x++)
//{
%>

Pleae help me.

Thanking you,
Vinith
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-31-2008, 05:08 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,223
Norm is on a distinguished road
What is displayed by out.println(num)? Is num a String of numeric characters or ?
Should your code test for num == null?
What is the error message?
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 08-01-2008, 07:20 AM
Member
 
Join Date: Jul 2008
Posts: 19
thusa is on a distinguished road
Before calling parseInt() method, you better check whether the value is null, since this method would throws a NPE.

It would be easy for us, if you had pasted the error message here.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 08-01-2008, 08:47 AM
Member
 
Join Date: Jul 2008
Posts: 2
vinikz is on a distinguished road
Hi,

I given condition for checking null value. Now my program is running well.

Thank you so much.......
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 08-01-2008, 08:52 AM
Member
 
Join Date: Jul 2008
Posts: 19
thusa is on a distinguished road
Glad that it's working.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Method to write if the string object can be converted to Integer or not. Abhishek New To Java 4 03-25-2008 02:16 PM
bytearray to string conversion mew New To Java 1 01-28-2008 12:39 PM
Method for String to int conversion Java Tip Java Tips 0 01-02-2008 08:35 PM
String to Integer conversion eva New To Java 2 12-17-2007 05:59 PM
String to Date conversion javaplus New To Java 2 11-06-2007 09:16 PM


All times are GMT +3. The time now is 12:40 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org