Twitter4J抛出异常java.lang.NoSuchMethodError:

时间:2013-07-24 14:08:16

标签: java twitter twitter-oauth twitter4j

无法获取推特实例,请建议我做错了

代码:

String consumerKey = "************************";

    //Your Twitter App's Consumer Secret
    String consumerSecret = "********************";

    //Your Twitter Access Token
    String accessToken = "**********************************";

    //Your Twitter Access Token Secret
    String accessTokenSecret = "*****************************";

    //Instantiate a re-usable and thread-safe factory
    TwitterFactory twitterFactory = new TwitterFactory();

    //Instantiate a new Twitter instance
    Twitter twitter = twitterFactory.getInstance(); /// **problem comes over here**

    twitter.setOAuthConsumer(consumerKey, consumerSecret);

    twitter.setOAuthAccessToken(new AccessToken(accessToken, accessTokenSecret));
从twitter v1迁移到v1.1时

  

java.lang.NoSuchMethodError:twitter4j.TwitterFactory.getInstance(Ltwitter4j / auth / AccessToken;)Ltwitter4j / Twitter;       在com.verve.meetin.twitter.twitterAuthenticationServlet.doGet(twitterAuthenticationServlet.java:151)       在javax.servlet.http.HttpServlet.service(HttpServlet.java:690)       在javax.servlet.http.HttpServlet.service(HttpServlet.java:803)       在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)       在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)       在org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:176)       at org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:145)       at org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:92)       at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:381)       在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)       在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)       在org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)       在org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)       在org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)       在org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)       在org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)       在org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)       在org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)       在org.apache.coyote.http11.Http11Protocol $ Http11ConnectionHandler.process(Http11Protocol.java:581)       在org.apache.tomcat.util.net.JIoEndpoint $ Worker.run(JIoEndpoint.java:447)       在java.lang.Thread.run(Thread.java:619)   INFO-内部用户即将到来的旅行

1 个答案:

答案 0 :(得分:3)

我用最新发布的版本(3.0.3)尝试了你的代码并编译完成,运行正常。

我认为您可能在类路径上有两个不同版本的Twitter4J,或者您正在使用一个版本进行编译并与另一个版本一起运行。一个版本将具有该方法而另一个版本将不具有该方法。

请注意,版本2.1.9及更早版本中引入了TwitterFactory#getInstance(AccessToken),这是异常报告的缺失方法。