Java“无法从元素类型Object转换为String”

时间:2012-05-18 23:05:37

标签: java

/*     */   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行返回错误“类型不匹配:无法从元素类型对象转换为字符串”。为什么会出现此错误?

1 个答案:

答案 0 :(得分:5)

更改为:

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

确保该方法返回List<String>而不只是List