Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
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 05-14-2008, 10:43 AM
Member
 
Join Date: May 2008
Posts: 8
thevoice is on a distinguished road
[SOLVED] Exception in thread "main" java.util.NoSuchElementException
Hello there,
I need to store resultset values in arrays.
Following is my code:
(Note : The function uses the jdbc connection with mysql that is return from other function.)
public static void getResultSetInArray(Connection con) throws Exception
{
Map list = new HashMap();
Statement stmt = con.createStatement(ResultSet.TYPE_FORWARD_ONLY,Re sultSet.CONCUR_READ_ONLY);
ResultSet rs = stmt.executeQuery("show columns from launchcomm.events");
while(rs.next())
{
list.put(rs.getString("Field"),rs.getString("Type" ));
}
rs.close();
con.close();
System.out.println("List = " + list + "\n");
Iterator iter = null;
iter = list.keySet().iterator();
System.out.println("iter = " + iter);
String field;
String type;
int i=1;
System.out.println("list size = " + list.size());

while(iter.hasNext() != false)
{
System.out.println("iter.hasNext() = " + iter.hasNext() +"......" +(i++));
System.out.println("iter.next() = " + iter.next());
field = (String)iter.next();
type = (String)list.get(iter.next());
}
}
----
Following is my output with error:
List = {folder_name=varchar(50), is_repeat=tinyint(1), footer=text, thankyou_email=text, box_header_bg_color=varchar(25), organization_id=int(11), attendee_delete_right=tinyint(1), show_ticket_remaining=tinyint(1), order_confirmation_email=text, save_for_later=tinyint(1), start_register=tinyint(4), id=int(11), logo=varchar(100), publish=tinyint(1), end_unregister=datetime, owner_id=int(11), confirmation_email=text, audience_id=int(11), event_color_code=varchar(30), showcalendar=tinyint(1), registration_enddate=datetime, directory_name=varchar(20), eventstatus_id=int(11), contact_id=int(11), password_protect=tinyint(1), include_header=tinyint(1), thankyou_page=text, header=text, is_hotel_capacity=tinyint(1), want_close=tinyint(1), travel_housing_request=tinyint(1), box_header_text_color=varchar(25), default_location_id=int(11), end_reg_modification=datetime, user_id=int(11), passkey_eventcode=varchar(255), page_size=int(11), passkey_password=varchar(255), event_capacity=int(11), box_text_color=varchar(25), updated_on=datetime, link_color=varchar(25), ends_on=datetime, hotel_capacity=int(11), template_id=int(11), allow_overlap_session=tinyint(1), starts_on=datetime, reg_another_button=varchar(50), passkey_partnerid=int(11), personalized_url=tinyint(1), hide_start_date=tinyint(1), hide_end_date=tinyint(1), include_footer=tinyint(1), text_color=varchar(25), allow_another_registrant=tinyint(1), passkey_eventid=int(11), resize=tinyint(1), default_closetemplate=tinyint(1), dateformat=text, personalize_agenda=tinyint(1), cssfile_id=int(11), passkey_information=tinyint(1), confirmation_page=text, activate_waitlist=tinyint(1), box_border_color=varchar(25), google_analytics_code=text, show_iframe_design=tinyint(1), confirmation_mail_format=tinyint(1), url=varchar(100), bg_color=varchar(25), package_id=int(11), name=varchar(200), password=varchar(50), capacity=int(11), modify_registration=tinyint(1), is_event_capacity=tinyint(1), include_css=tinyint(1), passkey_username=varchar(255), created_on=datetime, promote_url=varchar(100), page_views=int(11), box_bg_color=varchar(25), title_text_color=varchar(25), registration_open_text=text, require_login=tinyint(1), closetemplate_description=text, registration_startdate=datetime, domain=varchar(200), timezone_id=varchar(100), description=text, tag=varchar(255), allow_unregister=tinyint(1), order_confirmation_page=text, css=text, showmap=tinyint(1)}

iter = java.util.HashMap$KeyIterator@18a47e0
list size = 95
iter.hasNext() = true......1
iter.next() = folder_name
iter.hasNext() = true......2
iter.next() = footer
iter.hasNext() = true......3
iter.next() = box_header_bg_color
iter.hasNext() = true......4
iter.next() = attendee_delete_right
iter.hasNext() = true......5
iter.next() = order_confirmation_email
iter.hasNext() = true......6
iter.next() = start_register
iter.hasNext() = true......7
iter.next() = logo
iter.hasNext() = true......8
iter.next() = end_unregister
iter.hasNext() = true......9
iter.next() = confirmation_email
iter.hasNext() = true......10
iter.next() = event_color_code
iter.hasNext() = true......11
iter.next() = registration_enddate
iter.hasNext() = true......12
iter.next() = eventstatus_id
iter.hasNext() = true......13
iter.next() = password_protect
iter.hasNext() = true......14
iter.next() = thankyou_page
iter.hasNext() = true......15
iter.next() = is_hotel_capacity
iter.hasNext() = true......16
iter.next() = travel_housing_request
iter.hasNext() = true......17
iter.next() = default_location_id
iter.hasNext() = true......18
iter.next() = user_id
iter.hasNext() = true......19
iter.next() = page_size
iter.hasNext() = true......20
iter.next() = event_capacity
iter.hasNext() = true......21
iter.next() = updated_on
iter.hasNext() = true......22
iter.next() = ends_on
iter.hasNext() = true......23
iter.next() = template_id
iter.hasNext() = true......24
iter.next() = starts_on
iter.hasNext() = true......25
iter.next() = passkey_partnerid
iter.hasNext() = true......26
iter.next() = hide_start_date
iter.hasNext() = true......27
iter.next() = include_footer
iter.hasNext() = true......28
iter.next() = allow_another_registrant
iter.hasNext() = true......29
iter.next() = resize
iter.hasNext() = true......30
iter.next() = dateformat
iter.hasNext() = true......31
iter.next() = cssfile_id
iter.hasNext() = true......32
iter.next() = confirmation_page
iter.hasNext() = true......33
iter.next() = box_border_color
iter.hasNext() = true......34
iter.next() = show_iframe_design
iter.hasNext() = true......35
iter.next() = url
iter.hasNext() = true......36
iter.next() = package_id
iter.hasNext() = true......37
iter.next() = password
iter.hasNext() = true......38
iter.next() = modify_registration
iter.hasNext() = true......39
iter.next() = include_css
iter.hasNext() = true......40
iter.next() = created_on
iter.hasNext() = true......41
iter.next() = page_views
iter.hasNext() = true......42
iter.next() = title_text_color
iter.hasNext() = true......43
iter.next() = require_login
iter.hasNext() = true......44
iter.next() = registration_startdate
iter.hasNext() = true......45
iter.next() = timezone_id
iter.hasNext() = true......46
iter.next() = tag
iter.hasNext() = true......47
iter.next() = order_confirmation_page
iter.hasNext() = true......48
iter.next() = showmap
Exception in thread "main" java.util.NoSuchElementException
at java.util.HashMap$HashIterator.nextEntry(HashMap.j ava:844)
at java.util.HashMap$KeyIterator.next(HashMap.java:87 7)
at GetDataTypeFromDB.getResultSetInArray(GetDataTypeF romDB.java:57)
at GetDataTypeFromDB.main(GetDataTypeFromDB.java:16)

---
I am unable to fine the reason for the exception.
Please help me to solve my problem.
Regards,
Thevoice
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-14-2008, 12:42 PM
rjuyal's Avatar
Senior Member
 
Join Date: Mar 2008
Location: Delhi, India
Posts: 187
rjuyal is on a distinguished road
Code:
while(iter.hasNext() != false) { System.out.println("iter.hasNext() = " + iter.hasNext() +"......" +(i++)); System.out.println("iter.next() = " + iter.next()); field = (String)iter.next(); type = (String)list.get(iter.next()); } }
convert this to:

Code:
while(iter.hasNext()) { System.out.println("iter.hasNext() = " + iter.hasNext() +"......" +(i++)); field = (String)iter.next(); System.out.println("iter.next() = " + field); type = (String)list.get(field); } }
What mistake was in your code was, u checked whether iterator is having NextElem if yes then get next 3 elems , that is, probably, not what you wanted.
__________________
i am the future
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 05-14-2008, 01:44 PM
Member
 
Join Date: May 2008
Posts: 8
thevoice is on a distinguished road
Exception in thread "main" java.util.NoSuchElementException
Hello Mr.Rakesh
First of all thank you very much for your reply.
As you suggest me to change "while(iter.hasNext() != false)" to "while(iter.hasNext())".
I made that changes but error is still coming.
I wanna to know the reason of such error.
Can you explain me why such error occurs?
Is anything wrong in my code?

Regards,
TheVoice.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 05-14-2008, 01:48 PM
rjuyal's Avatar
Senior Member
 
Join Date: Mar 2008
Location: Delhi, India
Posts: 187
rjuyal is on a distinguished road
o dear, read my earlier post carefully it was not about changing
while(iter.hasNext() != false)" to "while(iter.hasNext())".

it was about using iter.next only once in loop

you used it thrice, please read my earlier post
__________________
i am the future
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 05-14-2008, 02:00 PM
Member
 
Join Date: May 2008
Posts: 8
thevoice is on a distinguished road
Exception in thread "main" java.util.NoSuchElementException
Hello Again Mr Rakesh
Thanks a LOT to make me correct.
My error get solved.
And i am sorry that i am unable to get what you trying to say in your reply


Regards,
TheVoice
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 05-14-2008, 02:43 PM
rjuyal's Avatar
Senior Member
 
Join Date: Mar 2008
Location: Delhi, India
Posts: 187
rjuyal is on a distinguished road
close the thread
ok, now close the thread as solved
__________________
i am the future
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
ERROR: Exception in thread "main" java.lang.NoSuchMethodError: main barney New To Java 1 08-07-2007 08:10 AM
Exception in thread "main" java.lang.NoClassDefFoundError carl New To Java 2 08-01-2007 06:26 AM
Exception in thread "main" java.net.ConnectException: Connection timed out osval Advanced Java 1 07-27-2007 11:59 PM
Error: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException romina New To Java 1 07-25-2007 11:55 PM
ArrayList: Exception in thread "main" java.lang.NullPointerException susan New To Java 1 07-16-2007 07:32 AM


All times are GMT +3. The time now is 02:45 AM.


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