java - jLabel.setVisible(true) doesn't work -


public class game extends javax.swing.jframe { arraylist<integer> numere = new arraylist<>(); arraylist<bila> balls = new arraylist<bila>(); arraylist<string> culori = new arraylist<>(); arraylist<jlabel> colours = new arraylist<>(); random random = new random(); jframe frame = new jframe("display image"); jpanel panel = (jpanel)frame.getcontentpane(); int nrballs=0;  public void createcolours(){     for(int i=0;i<7;i++){         culori.add("portocaliu");         culori.add("rosu");         culori.add("albastru");         culori.add("verde");         culori.add("negru");         culori.add("galben");         culori.add("violet");     } } public void createnumbers(){     for(int i=1;i<50;i++){         numere.add(i);     } } public void createballs(){     while(nrballs<36){         int indx =random.nextint(numere.size());         int nr = numere.get(indx);         numere.remove(indx);         string culoare = culori.get(indx);         culori.remove(indx);         balls.add(new bila(culoare,nr));         nrballs++;     } private void jbutton1mouseclicked(java.awt.event.mouseevent evt) {                                           for(int i=0;i<35;i++){         if(balls.get(i).culoare.equals("portocaliu")){             jlabel2.setvisible(true);         }     }  }   public static void main(string args[]) { game game = new game(); game.createcolours(); game.createnumbers(); game.createballs(); game.afisare(); }   } public class bila { int nr; string culoare; bila(string culoare,int nr){     this.nr = nr;     this.culoare = culoare; } 

when click button want find in array first ball respective colour , jlabel appear. indexoutofboundsexception index:0 size:0. know causing this? array list not empty, made method print out elements in array , it's not empty. stack trace:

exception in thread "awt-eventqueue-0" java.lang.indexoutofboundsexception: index: 0, size: 0     @ java.util.arraylist.rangecheck(arraylist.java:653)     @ java.util.arraylist.get(arraylist.java:429)     @ turbo6.game.jbutton1mouseclicked(game.java:154)     @ turbo6.game.access$100(game.java:15)     @ turbo6.game$2.mouseclicked(game.java:101)     @ java.awt.awteventmulticaster.mouseclicked(awteventmulticaster.java:270)     @ java.awt.component.processmouseevent(component.java:6538)     @ javax.swing.jcomponent.processmouseevent(jcomponent.java:3324)     @ java.awt.component.processevent(component.java:6300)     @ java.awt.container.processevent(container.java:2236)     @ java.awt.component.dispatcheventimpl(component.java:4891)     @ java.awt.container.dispatcheventimpl(container.java:2294)     @ java.awt.component.dispatchevent(component.java:4713)     @ java.awt.lightweightdispatcher.retargetmouseevent(container.java:4888)     @ java.awt.lightweightdispatcher.processmouseevent(container.java:4534)     @ java.awt.lightweightdispatcher.dispatchevent(container.java:4466)     @ java.awt.container.dispatcheventimpl(container.java:2280)     @ java.awt.window.dispatcheventimpl(window.java:2750)     @ java.awt.component.dispatchevent(component.java:4713)     @ java.awt.eventqueue.dispatcheventimpl(eventqueue.java:758)     @ java.awt.eventqueue.access$500(eventqueue.java:97)     @ java.awt.eventqueue$3.run(eventqueue.java:709)     @ java.awt.eventqueue$3.run(eventqueue.java:703)     @ java.security.accesscontroller.doprivileged(native method)     @ java.security.protectiondomain$javasecurityaccessimpl.dointersectionprivilege(protectiondomain.java:76)     @ java.security.protectiondomain$javasecurityaccessimpl.dointersectionprivilege(protectiondomain.java:86)     @ java.awt.eventqueue$4.run(eventqueue.java:731)     @ java.awt.eventqueue$4.run(eventqueue.java:729)     @ java.security.accesscontroller.doprivileged(native method)     @ java.security.protectiondomain$javasecurityaccessimpl.dointersectionprivilege(protectiondomain.java:76)     @ java.awt.eventqueue.dispatchevent(eventqueue.java:728)     @ java.awt.eventdispatchthread.pumponeeventforfilters(eventdispatchthread.java:201)     @ java.awt.eventdispatchthread.pumpeventsforfilter(eventdispatchthread.java:116)     @ java.awt.eventdispatchthread.pumpeventsforhierarchy(eventdispatchthread.java:105)     @ java.awt.eventdispatchthread.pumpevents(eventdispatchthread.java:101)     @ java.awt.eventdispatchthread.pumpevents(eventdispatchthread.java:93)     @ java.awt.eventdispatchthread.run(eventdispatchthread.java:82) 


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -