• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

awt radio button

 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,i inserted "lastadded" choice at 1000 position,
when i access getItem(555) it compiles,but gives me arrayoutofboundsException....
1. if i insert item at 1000 position, is it not that i have total 1000 of them and others are blank?
import java.awt.*;
class mychoice extends Frame{
public static void main (String args[])
{
new mychoice();
}
mychoice()
{
Choice c1 = new Choice();
c1.add("First");
c1.addItem("Second");
c1.add("Third");
c1.insert("Lastadded",1000);
System.out.println(c1.getItemCount());
System.out.println(c1.getItem(555));
}
}
 
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is kinda half baked .
The compiler beleives that c1 could probably be changed by an outside code & hence it lets u compile . But during runtime no such thing happens & there are no 1000 index in c1 . The index that exist are 0 to 3 . Hence the exception thrown is
java.lang.ArrayIndexOutOfBoundsException: 555 >= 4
Though i don't know how i could access c1 thru some other code , i sure can access the constructor like in this code
class Ash extends mychoice{
public static void main(String[]ka){
new Ash();
}
Ash(){
super();
}
};
Somebody tell me how i can access c1 & change its values ???
It's already 4 in the morn n i need to sleep .
 
srinivas bolloju
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi, u cannot edit items.....u can remove items and add diff items if u want,
for that remove() will help and then add() or addItem() will help
 
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The code for <code>insert</code> uses a Vector to store elements before the insert index and then calls Vector.addElement(item) which adds the element at the end of the Vector. As you've only got 4 elements <code>insert(item, 1000)</code> ends up being stored at index 4. See the source code for <code>insert()</code>

Hope that helps.
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform
[This message has been edited by Jane Griscti (edited July 15, 2001).]
 
Ashish Hareet
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey sri , what i wannna do is manipulate u'r object c1 from my class Ash ! Any suggestions ? I've posted a few replies to some other of u'r queries on the board
 
reply
    Bookmark Topic Watch Topic
  • New Topic