-1

I am trying to use a .jar file for prettifying my code(in app). For this I have found an answer to a question here

 private static Map<String, String> buildColorsMap() {
    Map<String, String> map = new HashMap<>();
    map.put("typ", "87cefa");
    map.put("kwd", "00ff00");
    map.put("lit", "ffff00");
    map.put("com", "999999");
    map.put("str", "ff4500");
    map.put("pun", "eeeeee");
    map.put("pln", "ffffff");
    return map;
}

To use this new Hashmap with <> angle brackets, I need to use Java 1.7 (which requires minSdk version of 18). When I update my compiler complaiance level to use 1.7, I get an error in my project, so need to clean. Once I clean the project, I get errors on my R.layout.XXX lines. It seems to be messing with this call to UI elements everywhere. Does anybody have any clue how to fix this issue?

Community
  • 1
  • 1
Cen92
  • 171
  • 1
  • 13

1 Answers1

1

Firstly, language level 7 can be used with any minSdkVersion as long as your targetSdkVersion is 18 or above. The only thing that requires a minSdkVersion bump is the try-with-resources syntax, which requires a minSdkVersion of 19 (KitKat).

How are you updating your language level? If you're using IntelliJ/Android Studio, you need to go to your Project Structure, and select Language Level 7, then restart your IDE and rebuild. If the only reason you're changing this is to use the above code, and you're having issues, you can just make it work with language level 6 by changing new HashMap<>() to new HashMap<String, String>().

Kevin Coppock
  • 133,643
  • 45
  • 263
  • 274