Hi.
I get an (identifier) expected error when I try to write my code.

The error message is:

"PathFinder.java:25: (identifier) expected
TList.setSelectionMode(ListSelectionModel.SINGLE.SELECTION);

"PathFinder.java:25: (identifier) expected
TList.setSelectionMode(ListSelectionModel.SINGLE.SELECTION);

My code looks like this:

import...

class PathFinder extends JFrame {
    Karta karta;
    JFileChooser jfc = new JFileChooser(".");
    int RitNR;
    JButton NP;
    ListGraph g = new ListGraph();
    ArrayList<String> stader = new ArrayList<String>();
    private DefaultListModel DefListMod = new DefaultListModel();
    private JList TList = new JList(DefListMod);
    private JList FList = new JList(DefListMod);
    TList.setSelectionMode(ListSelectionModel.SINGLE.SELECTION); // I don't understand 
                                                                    why it doesn't work
                                                                    here

...

A statement like that needs to be inside a method (eg the constructor)*

* yes,there are other places, but they're not in the Java 101 syllabus.

commented: Short. To the point. Helpful. +3
Member Avatar
hfx642

Once you have done what JamesCherrill said,
Try using... SINGLE_SELECTION instead of SINGLE.SELECTION

commented: Good catch! (correcting an answer that was *almost* perfect.) +3

Methods need to be called from within other methods, which are called from within other methods, etc, going back until your 'public void main(String[] args)' method. Outside the method structures in your class you can only create variables.