[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 534
  • Last Modified:

How to assign and use objects in an array?

I want to create 20 JLabel objects and in my loop, use the setText and setIcon methods to set object(s).  What am I doing wrong?

Here's the error I get:

E:\tech\java\gui>javac Button1.java -d .
Button1.java:54: cannot resolve symbol
symbol  : class JLable
location: class Button1
                lab[i] = new JLable();
1 error

Here's a code exerpt:

     try {
            JLabel[] lab = new JLabel[20];
            // instantiate and populate a collections object
            Collections colls = vs.collectionsInfo();
          //loop through colections object in order to get the individual collection objects (c0)
          for (int i=0; i < colls.size(); i++)
                lab[i] = new JLable();  // LINE 54
              Collection c0 = colls.at(i);
              String state = c0.getStateMeaning();
              if (state.equals ("offline"))
                 lab[i].setText("online coll");
            } catch (com.verity.k2.K2Exception e){
1 Solution
typo, should be:

  lab[i] = new JLabel();

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now