Question

So I have this button listener and when I compile it I get an incompatible type error. It says that a string is required and an object is found. Everything is imported. The MapCreator method creates a HashMap. Any ideas what I'm doing wrong? Also this class is a subclass of my GUI class and MapCreator is a class in a separate file but in the same folder.

private class searchListener extends MapCreator implements ActionListener{
    public void actionPerformed(ActionEvent e){
        try{
            Map urls = MapCreator();
            String input = textfield.getText();
            if(urls.containsKey(input)){
                String key = urls.get(input);
                gloss.setPage("http://www.catb.org/jargon/html/"+key);
            }else{
                JFrame error = new JFrame("Error");
                JLabel mesasge = new JLabel("This word does not exist");
            }
        }catch(FileNotFoundException s){

        }
    }

}
Était-ce utile?

La solution

Parametrize the Map:

Map<String, String> urls = MapCreator();

The get() method of a raw Map returns an Object.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top