2017-01-28 1 views
-2

콘솔이 라인에서 오류 메시지를 보낼 수있는 오류 (154)자바 bukkit - 문자열 message.replace ("&", "§")

//files 
    //mensagens.yml 
    ServerTag: '&0[&cServer&0] ' 
    SugVipAnotada: '&aSua sugestao foi recebida e anotada! e por ser vip sera lida primeiro!' 


//Code: 
    //in onEnable: 
       File file1 = new File(getDataFolder(), "mensagens.yml"); 
     if (!file1.exists()) { 
      try{ 
       saveResource("mensagens.yml", false); 
      } 
      catch (Exception localException) {} 
      } 

    //in onCommand: 

     try { 
      config.load(configL); 
     } catch (IOException | InvalidConfigurationException e1) { 
      e1.printStackTrace(); 
     } 
/*ERROR*/sender.sendMessage(config.getString("ServerTag").replace("&", "§") + config.getString("SugVipAnotada").replace("&", "§")); 

난 오류가 발생했습니다 이유의 생각이없는

관찰 : 나는 브라질의 나는 왜 플러그인은 포르투갈어 번역 : 앞으로

+0

전체 오류 및 스택 추적을 표시하십시오. – Li357

+0

154 줄은 어느 쪽입니까 ?? –

답변

1

(텍스트의 전체 줄 이상입니다), 가능한 한 필수 세부로 제공하십시오. NullPointerException이 구성 항목 ServerTag 또는 SugVipAnotada을 찾을 수 없기 때문에 NullPointerException이 getString()에 의해 던져 질 가능성이 있습니다.

결과가 Null인지 먼저 확인하거나 기본값을 제공해야합니다. 예를 들어. 색 변환 (&§에)에 관해서

String serverTag = config.getString("ServerTag"); 
if (serverTag == null) { 
    // Bark some error or throw exception if value is expected 
} 

또는

String serverTag = config.getString("SeverTag", "some def value"); 

: replace() 실제로 당신이 원하는하지 그 모든 &§로 대체됩니다있다. 경우 &이 메시지의 일부인 경우 Bait에 오신 것을 환영합니다 & 태클입니다. replaceAll()을 사용하고 regex를 활용하면 변환해야하는 것을 변환하는 것이 좋습니다. 당신은 원시 텍스트를 얻기 위해 어떤 색상의 주석을 제거하려면

msg.replaceAll("(?i)&([0-9A-FK-OR])", "§$1") 

, 당신은 내가이 도움이 당신이가는 할텐데

msg.replaceAll("(?i)(&|§)[0-9A-FK-OR]", "") 

를 사용할 수 있습니다. 플러그인 번역의 나머지와 함께 행운을 빈다.