Page 1 of 2 12 LastLast
Results 1 to 20 of 33
  1. #1
    macwadu is offline Member
    Join Date
    Jun 2010
    Posts
    29
    Rep Power
    0

    Default Multidemensional array of Buttons

    Hi there, i have question how do i do this, its giving me a error when i create the new client_array_l2 with a string inside.

    Can anyone help me?


    Java Code:
    static JButton[][] client_array_l2;
    
    
    client_array_l2[Conn.t4][aux2] = new JButton(Conn.string_array_PIDName[aux2]);

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

    Default

    Quote Originally Posted by macwadu View Post
    Hi there, i have question how do i do this, its giving me a error when i create the new client_array_l2 with a string inside.
    What error precisely is it giving you. Please read my second signature link for more information on what information we need in order to be able to give an intelligent answer to a question here.

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Yes, provide more details about the question such as what Conn.string_array_PIDName[aux2] is return and so on.

  4. #4
    macwadu is offline Member
    Join Date
    Jun 2010
    Posts
    29
    Rep Power
    0

    Default

    Conn.string_array_PIDName[aux2] is an array of strings

    that is in a cycle wild to run all the elements and put in client_array_l2[Conn.t4][aux2]

    where con is a a integer and is incremented every time cycle wild is called
    aux2 is a local variable to run the cycle until the number of elements of the array Conn.string_array_PIDName[aux2]


    I don't know if this is enough for you too understand

    Tanks

  5. #5
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,783
    Blog Entries
    7
    Rep Power
    21

    Default

    But what was the error exactly?

    kind regards,

    Jos

  6. #6
    macwadu is offline Member
    Join Date
    Jun 2010
    Posts
    29
    Rep Power
    0

    Default

    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException

    then he writes some output made by me and when creating the multidemensional array breaks there and tell me this line client_array_l2[Conn.t4][aux2] = new JButton(Conn.string_array_PIDName[aux2]);


    the aux2 = 0
    and Conn.t4 = 0

    for the frist position

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

    Default

    Quote Originally Posted by macwadu View Post
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    I asked for this in the first reply to your thread, but you need to tell us more. Which line is causing the NPE to be thrown? If you know this, you can find out which object there is null and fix it.
    Last edited by Fubarable; 08-27-2010 at 01:13 PM.

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    Does your code assign a value to client_array_l2?

    Something like: client_array_l2 = new ...

    Your sample code defines it but does not show it being given a value.

  9. #9
    macwadu is offline Member
    Join Date
    Jun 2010
    Posts
    29
    Rep Power
    0

    Default

    static JButton[][] client_array_l2;

    client_array_l2 = new JButton[200][200];

    client_array_l2[Conn.t4][aux2] = new JButton(Conn.string_array_PIDName[aux2]);



    what you are saing is that i have to inicialize the JButton[][] with some int?

  10. #10
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    Arrays, like other variables, must be assigned values otherwise they are null.

    have to initialize the JButton[][] with some int
    The size/dimensions is set by the int values. The array itself still contains null values.

  11. #11
    macwadu is offline Member
    Join Date
    Jun 2010
    Posts
    29
    Rep Power
    0

    Default

    Java Code:
    cli = new JButton[200][200];
    cli[Conn.t4][y] = client_array_l2[Conn.num_pid];
    
    
    while(Conn.num_pid != aux2 ){
       
       client_array_l2[aux2] = new JButton(Conn.string_array_PIDName[aux2]);
       client_array_l2[aux2].setName("b1"+aux2);
    
    }
    is giving me an error in here cli[Conn.t4][y] = client_array_l2[Conn.num_pid];

    is not accepting to put JButton client_array_l2[] to the multidimensional JButton cli[][] and i dont know why

  12. #12
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    is giving me an error
    please copy and paste the full text of the error message. My crystal ball is in the shop.

  13. #13
    macwadu is offline Member
    Join Date
    Jun 2010
    Posts
    29
    Rep Power
    0

    Default

    :)

    ---------------------------
    Level: 0
    Estao todos fechados
    xzcasd2 TMN
    xzcasd2 TMN
    Conn.num_pid: 9
    aux2: 0
    Conn.string_array_PIDName[aux2]: TMN
    t1: 0
    t4: 1
    Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 9
    at Project.f.CreateButtons(f.java:275)
    at Project.f.cria(f.java:138)
    at Project.f$1.mouseClicked(f.java:93)
    at java.awt.AWTEventMulticaster.mouseClicked(AWTEvent Multicaster.java:253)
    at java.awt.Component.processMouseEvent(Component.jav a:6266)
    at javax.swing.JComponent.processMouseEvent(JComponen t.java:3267)
    at java.awt.Component.processEvent(Component.java:602 8)
    at java.awt.Container.processEvent(Container.java:204 1)
    at java.awt.Component.dispatchEventImpl(Component.jav a:4630)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2099)
    at java.awt.Component.dispatchEvent(Component.java:44 60)
    at java.awt.LightweightDispatcher.retargetMouseEvent( Container.java:4574)
    mouseExited
    at java.awt.LightweightDispatcher.processMouseEvent(C ontainer.java:4247)
    at java.awt.LightweightDispatcher.dispatchEvent(Conta iner.java:4168)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2085)
    at java.awt.Window.dispatchEventImpl(Window.java:2478 )
    at java.awt.Component.dispatchEvent(Component.java:44 60)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java: 599)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:269)
    at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:184)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:174)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:169)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:161)
    at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:122)

  14. #14
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 9
    at Project.f.CreateButtons(f.java:275)
    The array referenced at line 275 does not have an element at index=9

    Look at that line of code and see how the index(es) to the array can be 9.
    What is the size of the array dimension(s) at that statement?

  15. #15
    macwadu is offline Member
    Join Date
    Jun 2010
    Posts
    29
    Rep Power
    0

    Default

    Tanks you have solved my error, in the cli array in position 9 it hasnt any value in there.

    Another question if you can answer me:

    im calling a function over and over that creates the same array so when i want to access the values before i cant

    is there a way to increment the name of the array like this:

    array1[] - in the first passage
    array2[] - in the second

    and so on

  16. #16
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    i want to access the values before i cant
    Not sure what you are asking here.
    Do you want to keep a copy of the array that the "function"/method changes?
    Use one of the Arrays class's copy methods to make a copy.

    is there a way to increment the name of the array like this
    Names are set at compile time.
    What is the purpose of "incrementing" the name of an array?

  17. #17
    macwadu is offline Member
    Join Date
    Jun 2010
    Posts
    29
    Rep Power
    0

    Default

    im calling a function over and over that creates the same array so when i want to access the values before they only have the last ones

    i dont want a copy i want o to create a distinct array that i can access anytime




    What is the purpose of "incrementing" the name of an array?

    when i say increment i mean that every time i call the function the array as a diferent name lke that

    array1[]
    array2[]
    array3[]

  18. #18
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    function over and over that creates the same array
    That seems wasteful. Why not create it only one time? Put the code to create it into a separate method and only call it once.

    call the function/method the array has a diferent name
    The names are set when the program is compiled.
    What purpose would changing the names have? Would the contents be the same or different? The method doesn't care what the name of the array is that is passed to it as an argument.

  19. #19
    macwadu is offline Member
    Join Date
    Jun 2010
    Posts
    29
    Rep Power
    0

    Default

    [x] -> this is array of buttons one
    [y] [z] [r] -> this is array of buttons two
    [v] [g] -> -> this is array of buttons three

    so i want to keep in an array the elements of each line so i can later know the array to remove

    the content is going to be diferent, that why i want the array to hava a diferent name

    the design is better to understand

    http://picasaweb.google.com/lh/photo...eat=directlink
    Last edited by macwadu; 08-27-2010 at 08:29 PM.

  20. #20
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    Sorry your posting makes no sense to me.
    [x] -> this is array of buttons one
    [y] [z] [r] -> this is array of buttons two
    [v] [g] -> -> this is array of buttons three
    Does the first line refer to a one dimension array of size x?
    And the second to a three dimensional array?
    and the third line to a 2 dim array?

    i want to keep in an array the elements of each line
    What is the problem "keeping" the arrays? If your code doesn't change their values they won't change.

    Can you make a small program to demonstrate your problem? I can not understand what you are asking.

Page 1 of 2 12 LastLast

Similar Threads

  1. Non functional radio buttons and messed up array
    By flameofSuzaku in forum New To Java
    Replies: 2
    Last Post: 01-10-2011, 06:38 PM
  2. Help with Buttons
    By wld4ubabay in forum New To Java
    Replies: 20
    Last Post: 05-17-2010, 09:13 AM
  3. Replies: 2
    Last Post: 04-30-2010, 04:06 AM
  4. Where To Get Pop Up Buttons
    By hitmen in forum AWT / Swing
    Replies: 7
    Last Post: 03-26-2009, 05:05 AM
  5. How to use SWT Buttons
    By Java Tip in forum SWT Tips
    Replies: 0
    Last Post: 07-11-2008, 05:44 PM

Posting Permissions

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