将twitter4j导入eclipse

zu0ti5jz  于 2021-06-30  发布在  Java
关注(0)|答案(1)|浏览(467)

我已经通过java构建路径将4个twitter4jjar文件导入到我的项目中,但是当我导入twitter4j.twitter;&导入twitter4j.twitterfactory;我得到一个运行时错误?由于导入[enter image description here][2]不起作用,声明对象的最后两行代码有一个红色下划线。当我突出显示前两个导入行时,会出现“包twitter4j可以从多个模块访问:org.twitter4j.core、twitter4j.async、twitter4j.examples、twitter4j.stream”错误。有人知道为什么吗?

import twitter4j.Twitter;
import twitter4j.TwitterFactory;
import twitter4j.conf.ConfigurationBuilder;

public class Main {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        ConfigurationBuilder cb = new ConfigurationBuilder();
        cb.setDebugEnabled(true)
          .setOAuthConsumerKey("*********************")
          .setOAuthConsumerSecret("******************************************")
          .setOAuthAccessToken("**************************************************")
          .setOAuthAccessTokenSecret("******************************************");
        TwitterFactory tf = new TwitterFactory(cb.build());
        Twitter twitter = tf.getInstance();
    }

}

我在执行时得到这个错误代码。

Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
    TwitterFactory cannot be resolved to a type
    TwitterFactory cannot be resolved to a type
    Twitter cannot be resolved to a type

    at Main.main(Main.java:15)
qni6mghb

qni6mghb1#

尝试导入:

import twitter4j.*;

也要这样做:

ConfigurationBuilder cb;
Twitter twitter;
cb = new ConfigurationBuilder();
twitter = new TwitterFactory(cb.build()).getInstance();

相关问题