1
/*     */   public static void printJoinChat(Player player) {
/*  41 */     FileConfiguration kitConfig = YamlConfiguration.loadConfiguration(new File(plugin.getDataFolder(), "kit.yml"));
/*  42 */     List kitname = kitConfig.getStringList("KITS");
/*     */ 
/*  44 */     String vipkit = "";
/*  45 */     String norkit = "";
/*  46 */     for (String name : kitname) {
/*  47 */       ConfigurationSection kit = kitConfig.getConfigurationSection(name.toLowerCase());
/*  48 */       if (kit.getBoolean("VIP")) {
/*  49 */         if (vipkit == "")
/*  50 */           vipkit = name;
/*     */         else {
/*  52 */           vipkit = vipkit + ", " + name;
/*     */         }
/*     */       }
/*  55 */       else if (norkit == "")
/*  56 */         norkit = name;
/*     */       else {
/*  58 */         norkit = norkit + ", " + name;
/*     */       }
/*     */ 
/*     */     }

此代码在第 46 行返回错误“类型不匹配:无法从元素类型 Object 转换为 String”。为什么会出现此错误?

4

1 回答 1

5

改成这样:

 List<String> kitname = kitConfig.getStringList("KITS");

确保该方法返回 aList<String>而不仅仅是 a List

于 2012-05-18T23:06:54.763 回答