Results 1 to 7 of 7
  1. #1
    relax1 is offline Member
    Join Date
    Dec 2010
    Posts
    3
    Rep Power
    0

    Default JTextField Array Read Error

    Java Code:
    public void addfields() {
            JTextField tfserie[]=new JTextField[100];
            tfserie[x] = new JTextField(15);
            tfserie[x].setText(serie.getText());
            c.gridx =0;
            c.gridy = x;
            c.gridwidth = 2;
            c.fill = GridBagConstraints.HORIZONTAL;
            p.add(tfserie[x],c);
    
            JTextField tfeps[]=new JTextField[100];
            tfeps[x] = new JTextField(5);
            tfeps[x].setText(eps.getText());
            c.gridx =2;
            c.gridy = x;
            c.gridwidth = 1;
            c.fill = GridBagConstraints.HORIZONTAL;
            p.add(tfeps[x],c);
            
    
                String data = "";
            for(int i=1;i<=x;i++) {
                data = data + tfserie[i].getText()+";";  <--------------------this 2lines is error
                data = data + tfeps[i].getText()+";"; 
                System.out.println(data);
            }
        }

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,785
    Blog Entries
    7
    Rep Power
    21

    Default

    You allocate 100 references to JTextFields (an array) and you only initialize one of them at index value 'x'. Later you want to do something with all text fields 1 .... x while only index number x contains a valid text field.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    relax1 is offline Member
    Join Date
    Dec 2010
    Posts
    3
    Rep Power
    0

    Default

    the program sould work like this

    you have 2textfields from start with 3buttons
    button1 new
    button2 save
    button3 load
    the code from above is from button1 new witch means it collects text from the 2starting fields and run the addfields()

    in addfields() there is a data collection witch is the thing i have problem with. the first time i press new everything is ok but as soon as there more then 1 press on new i get error message.

    yes i have 100 fields because then i don't have to worry about being to short

    don't know how more i can enplane it i don't realy get your anwser and how it can help me got any suggestions?

    and yeah x is how many times i have pressed new button e.g. how many new fields there is



    problem seems to be when i create tfserie[2] and tfeps[2] i cant read [1] anymore
    Last edited by relax1; 12-17-2010 at 09:11 PM.

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,785
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by relax1 View Post
    yes i have 100 fields becouse then i dont have to worry about beeing to short
    Why don't you use 1000, or even 10000 text field references then? I'm sorry I don't understand the intention of your code ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    relax1 is offline Member
    Join Date
    Dec 2010
    Posts
    3
    Rep Power
    0

    Default

    Quote Originally Posted by JosAH View Post
    Why don't you use 1000, or even 10000 text field references then? I'm sorry I don't understand the intention of your code ...

    kind regards,

    Jos
    i could have that but i just picked a number and that number isn't relevant
    the intention with the code is to read every tfserie[].gettext and tfeps[].gettext that has been created. the int value of x is the number of created textfields. every time you push a button the code is executed and new textfild's are created...

    hope thats enouf info
    Last edited by relax1; 12-17-2010 at 09:08 PM.

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Your posts are difficult to read, especially for volunteers who don't speak English as a primary or secondary language. Please have the consideration to edit your posts above and remove all non-standard abbreviations such as u and ur, and replace with standard English. Thank you for your cooperation.

  7. #7
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,457
    Rep Power
    20

    Default

    An uppercase letter at the beginning of each sentence and for hte first person singular would also go a long way to making those posts readable.

    Recommended reading: [url http://catb.org/~esr/faqs/smart-questions.html#writewell]Write Well[/url].

    db

Similar Threads

  1. Help ! Read from txt to array an than search
    By kram54 in forum New To Java
    Replies: 1
    Last Post: 12-09-2010, 12:52 AM
  2. Read user input into integer array
    By varunb in forum New To Java
    Replies: 12
    Last Post: 07-09-2010, 01:50 PM
  3. Read File into 2d array
    By almjodla in forum New To Java
    Replies: 8
    Last Post: 03-23-2010, 03:55 PM
  4. Replies: 1
    Last Post: 01-30-2009, 07:44 PM
  5. Replies: 5
    Last Post: 07-30-2008, 10:30 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •