2017-08-10 1768 views
0

我试图通过API来创建拼写检查程序,这里是我的代码java.lang.ClassCastException:org.apache.logging.slf4j.SLF4JLoggerContext不能转换到org.apache.logging.log4j.core.LoggerContext

SpellCheck.java

package com.spell; 

import org.xeustechnologies.googleapi.spelling.SpellChecker; 
import org.xeustechnologies.googleapi.spelling.SpellCorrection; 
import org.xeustechnologies.googleapi.spelling.SpellResponse; 

public class SpellCheck { 

    public static void main(String[] args) 
    { 

     SpellChecker checker = new SpellChecker(); 

     SpellResponse spellResponse = checker.check("helloo worlrd"); 

     for(SpellCorrection sc : spellResponse.getCorrections()) 
      System.out.println(sc.getValue()); 

    } 
} 

依赖

enter image description here

enter image description here

错误我它运行后得到:

Exception in thread "main" java.lang.ExceptionInInitializerError at com.spell.SpellCheck.main(SpellCheck.java:12) Caused by: java.lang.ClassCastException: org.apache.logging.slf4j.SLF4JLoggerContext cannot be cast to org.apache.logging.log4j.core.LoggerContext at org.apache.log4j.Logger$PrivateManager.getContext(Logger.java:59) at org.apache.log4j.Logger.getLogger(Logger.java:41) at org.xeustechnologies.googleapi.spelling.SpellChecker.(SpellChecker.java:50) ... 1 more

+0

这似乎是'org.xeustechnologies.googleapi.spelling.SpellChecker' API中的一个错误。 – paper1111

回答

0

它看起来像org.xeustechnologies.google.api.spelling.SpellChecker使用log4j,你正在使用SLF4J。尝试将log4j-over-slf4j添加到类路径以桥接log4以使用slf4j。

+0

删除所有log4j jar后,我只添加了2个jar(api-spell checker,log4j-over-slf4j-1.7),但运行程序后出现以下错误: –

+0

线程“main”异常java.lang.NoClassDefFoundError :org/slf4j/MarkerFactory \t at org.apache.log4j.Category。 (Category.java:53) \t at org.xeustechnologies.googleapi.spelling.SpellChecker。 (SpellChecker.java:50) \t在com.spell.SpellCheck.main(SpellCheck.java:12) 产生的原因:抛出java.lang.ClassNotFoundException:在org.slf4j.MarkerFactory \t java.net.URLClassLoader的$ 1.run (来源不明) \t在java.net.URLClassLoader的$ 1.run(来源不明) \t在java.security.AccessController.doPrivileged(本机方法) \t在java.net.URLClassLoader.findClass(来源不明) –

+0

看起来像你的类路径中没有slf4j API。添加slf4j-api.jar。 –

相关问题