Error in Java project: cannot find symbol

DjWarWick :

I am trying to build a project for school. It is a list with some combo boxes that have an effect over it. For now I am trying to build the interface and later implement utility. Here is the code:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;

class Grafica {
  static IUG iug = new IUG("Proiect"); //fereastra aplicatiei
  static AAL ascultLista = new AAL(); //ascultatorul selectiei in lista
  static AEA ascultOpt = new AEA(); //ascultatorul listelor ascunse

  static class IUG extends JFrame {
    JPanel optiuni = new JPanel(new GridLayout(3,1));
    JList lista;
    JComboBox comboDist, comboProd, comboTip;

    IUG(String titlu) {
      super(titlu);
      Container cp = getContentPane();

      //marimea ferestrei este setata pe baza rezolutiei ecranului
      Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
      double width = screenSize.getWidth();
      double height = screenSize.getHeight();
      setSize((int)width/4,(int)height/4);
      setLocation((int)width/3,(int)height/3);
      cp.setLayout(new BorderLayout());
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //se inchide programul daca inchidem fereastra

      String luni[] = {"Ianuarie", "Februarie", "Martie", "Aprilie",
         "Mai", "Iunie", "Iulie", "August", "Septembrie",
         "Octombrie", "Noiembrie", "Decembrie"};
      lista = new JList(luni);
      lista.setBorder(BorderFactory.createTitledBorder("Lista produselor"));
      //lista.setSelectModel(new DefaultListSelectionModel());
      //lista.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
      lista.addListSelectionListener(ascultLista);
      JScrollPane scroll = new JScrollPane(lista); //crearea panoului cu produsele aferente
      cp.add(scroll, BorderLayout.WEST);

      // crearea unui label unde se descriu produsele
      JLabel descriere = new JLabel();
      descriere.setBorder(BorderFactory.createTitledBorder("Descrierea produselor"));
      cp.add(descriere, BorderLayout.SOUTH);

      //Se creeaza listele ascunse ale optiunilor
      String tipuri[] = {"LED", "Neon", "Clasice", "Economice"};
      String distribuitori[] = {"EMAG", "Flanco", "Altex"};
      String producatori[] = {"Philips", "Star-Light", "TP-link"};
      comboTip = new JComboBox(tipuri);
      comboTip.setBorder(BorderFactory.createTitledBorder("Tipuri becuri"));
      comboTip.addItemListener(ascultOpt);
      optiuni.add(comboTip);

      comboDist = new JComboBox(distribuitori);
      comboDist.setBorder(BorderFactory.createTitledBorder("Distribuitori"));
      comboDist.addItemListener(ascultOpt);
      optiuni.add(comboDist);

      comboProd = new JComboBox(producatori);
      comboProd.setBorder(BorderFactory.createTitledBorder("Producatori"));
      comboProd.addItemListener(ascultOpt);
      optiuni.add(comboProd);

      cp.add(optiuni,BorderLayout.EAST);
      setVisible(true);
    }
  }

  static class AAL implements ListSelectionListener {
    public void valueChanged(ListSelectionEvent e) {
      JList sursa = (JList)e.getSource();
      Object selectie[] = sursa.getSelectedValues();
      StringBuffer buff = new StringBuffer();
      for(int i = 0; i < selectie.length; i++)
         buff.append(selectie[i].toString() + " ");
      iug.descriere.setText(buff.toString());
    }
  }

  static class AEA implements ItemListener {
    public void itemStateChanged(ItemEvent e) {
      iug.descriere.setText(e.getItem().toString());
    }
  }

  public static void main(String args[]) {
  }
}

But when I run it, it shows me this:

Grafica.java:76: error: cannot find symbol
      iug.descriere.setText(buff.toString());
         ^
  symbol:   variable descriere
  location: variable iug of type IUG
Grafica.java:82: error: cannot find symbol
      iug.descriere.setText(e.getItem().toString());
         ^
  symbol:   variable descriere
  location: variable iug of type IUG
Note: Grafica.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Grafica.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
2 errors

Any help is appreciated. I really cant figure out what I did wrong, even after many searches on Google.

güriösä :

That the reference to descriere is missing (cannot find symbol iug.descriere), since you define and create JLabel descriere in the consturctor only IUG(String titlu) instead of making it a class attribute (like lista e.g.). It has the wrong scope.

If you use a resonable IDE it will highlight the issue (well, mine did) without the need to explicitly compile before you run into it.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=357142&siteId=1