title: Java Array : Unable to store new values into an array
body: <p>I am getting battery values from a drone. I am able to display the new battery value on JLabel. However, when I am trying to store these battery values into an int array, it is only store the very first battery value on the array. The subsequent array values will only fill up with the first battery value. </p>
  
  <p>I show an output so you will understand what is happening. The first value is getting from drone while the second value indicate the array index. The output clearly show that the array cannot accept new data for unknown reason.</p>
  
  <p>P/S: I have no idea what is best size of array since I am getting values from drone every seconds. So I have declared an int array with size of 9999999. Any idea how can I set an array to its max size to cater the needs of getting continuous battery values from drone? Those values are being used for drawing graph later.</p>
  
  <p><strong>My code:</strong></p>
  
  <pre><code>public class arDroneFrame extends javax.swing.JFrame implements Runnable, DroneStatusChangeListener, NavDataListener {
  
        private String text; // string for speech
        private static final long CONNECT_TIMEOUT = 10000;
        public ARDrone drone;
        public NavData data;
        public Timer timer = new Timer();
        public int batteryGraphic=0;
        public int [] arrayBatt = new int[9999999];
  
        public arDroneFrame(String text) {
            this.text=text;          
        }
  
        public arDroneFrame() {
           initComponents();             
           initDrone();       
        }
  
        private void initDrone() {
          try {
            drone = new ARDrone();
            data = new NavData();          
          } catch (UnknownHostException ex) {
          return;     
        } 
          videoDrone.setDrone(drone);        
          drone.addNavDataListener(this);
  }
  
       public void navDataReceived(NavData nd) { 
           getNavData(nd);    
           int battery = nd.getBattery();  
           cmdListOK.jlblBatteryLevelValue.setText(battery + " %"); 
           //JLabel can get updated &amp; always display new battery values 
        }
  
       public void getNavData(NavData nd){
            for(int i=0;i&lt;arrayBatt.length;i++){
                batteryGraphic= nd.getBattery();
                arrayBatt[i] = batteryGraphic;
                System.err.println("This is stored battery values : " + arrayBatt[i] + "   " + i + "\n");
            }
       }
  }
  
       public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
               public void run() {
  
                String text = "Welcome!";
                arDroneFrame freeTTS = new arDroneFrame(text);
                freeTTS.speak();
  
                new arDroneFrame().setVisible(true);
                }
        });
     }
  </code></pre>
  
  <p><strong>Result:</strong></p>
  
  <pre><code>This is stored battery values : 39   0
  
  This is stored battery values : 39   1
  
  This is stored battery values : 39   2
  
  This is stored battery values : 39   3
  
  This is stored battery values : 39   4
  
  This is stored battery values : 39   5
  </code></pre>