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);
}
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
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With