无法解析符号变量 getSelectedIndex

Cannot resolve symbol variable getSelectedIndex

我在尝试复制和粘贴代码时遇到问题,它说了一些关于未格式化的内容??我不知道这是我的第一次,但这是麻烦的代码我会 link 一个 pastebin 这样你也可以看到

完整代码:http://pastebin.com/p6RQiSLz

有问题的代码:

    //City (JList with txtfield)

    pane.add(lblCity);
    lblCity.setForeground(Color.BLACK);
    lblCity.setBounds(5,260,80,25);

    pane.add(list);
    list.setSelectedIndex(0);
    list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    list.setBackground(Color.BLACK);
    list.setForeground(Color.WHITE);
    list.setBounds(90,260,150,100);
    list.setEnabled(false);
    pane.add(txtCity);
    txtCity.setBounds(90,380,150,25);

//================================TROUBLED BLOCK OF CODE============================================

    list.addListSelectionListener(new ListSelectionListener(){
        public void valueChanged(ListSelectionEvent er){
            txtCity.setText(listCity[listCity.getSelectedIndex]);
        }
    });

listCity 是一个数组,数组没有 getSelectedIndex 属性,甚至没有数组的 "selected element" 概念。您可能想要从 listCity 生成的 JList 上选择的项目,因此请尝试使用 list.getSelectedIndex() 而不是 listCity.getSelectedIndex。那至少应该编译。