0

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

...

Edited by Ezzaral: Added code tags. Please use them to format any code that you post.

4
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by Aviras
1

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.

Votes + Comments
Short. To the point. Helpful.
1

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

Edited by hfx642: n/a

Votes + Comments
Good catch! (correcting an answer that was *almost* perfect.)
1

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.