Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multi-catches are not supported a this language level

So I want to type a number, and then a name of a person or something else. There is no problem with that, but why can't I put 2 error exceptions in 1 block?

while (true) {
    try {
        int id = Integer.parseInt( reader.readLine() );
        String name = reader.readLine();

        if (name.equals("")) {
            break;
        }

        map.put(name, id);
    } catch (NumberFormatException | IOException e) {
        break;
    }
}

When I'm trying to print my value, I get NumberFormatException

for (Map.Entry<Integer, String> pair: map.entrySet()) {
    int id = pair.getKey();
    String name = pair.getValue();
    System.out.println(id + " " + name);
}
like image 679
Predict_it Avatar asked Mar 12 '14 21:03

Predict_it


2 Answers

If you are using IntelliJ and set it to 7.0 properly in the following path and still didn't work:

File -> Project Structure -> Project settings -> Project -> Project language level

Set in the module:

File -> Project Structure -> Project settings -> Modules -> Project language level

like image 120
gauti Avatar answered Nov 15 '22 15:11

gauti


In my case, an explicit configuration in my pom.xml did the trick. The IntelliJ setting in File -> Project Structure -> Project -> Project language level was set to my JDK 1.7 but the IDE kept ignoring the setting.

I used the Maven Compiler Plugin to specify the source and target version as 1.7

To do so, in the <plugins> section, add the following lines:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.5</version>
    <configuration>
        <source>1.7</source>
        <target>1.7</target>
    </configuration>
</plugin>
like image 35
toniedzwiedz Avatar answered Nov 15 '22 16:11

toniedzwiedz