Search code examples
javatwitter4j

incompatible type and can not find symbol in twitter4j?


this is what is the code and i get the problem in marked lines(BOLD), i think it is because of the jar version but i am not sure about this. if this is because of jar version please do let me know the right one.

import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;

    import twitter4j.Twitter;
    import twitter4j.TwitterException;
    import twitter4j.TwitterFactory;
    import twitter4j.auth.AccessToken;
    import twitter4j.auth.RequestToken;

    public class NamexTweet {
        private final static String CONSUMER_KEY = "xxxxxxxxxxxxx";
        private final static String CONSUMER_KEY_SECRET = "yyyyyyyyyyyyyyy";

        public void start() throws TwitterException, IOException {

     Twitter twitter = new TwitterFactory().getInstance();
     twitter.setOAuthConsumer(CONSUMER_KEY, CONSUMER_KEY_SECRET);
     **RequestToken requestToken = twitter.getOAuthRequestToken();**
     System.out.println("Authorization URL: \n"
      + requestToken.getAuthorizationURL());

     AccessToken accessToken = null;

     BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
     while (null == accessToken) {
         try {
      System.out.print("Input PIN here: ");
      String pin = br.readLine();

      **accessToken = twitter.getOAuthAccessToken(requestToken, pin);**

         } catch (TwitterException te) {

      System.out.println("Failed to get access token, caused by: "
       + te.getMessage());

      System.out.println("Retry input PIN");

         }
     }

     System.out.println("Access Token: " + accessToken.getToken());
     System.out.println("Access Token Secret: "
      + accessToken.getTokenSecret());

     twitter.updateStatus("hi.. im updating this using Namex Tweet for Demo");

        }

        public static void main(String[] args) throws Exception {
     new NamexTweet().start();// run the Twitter client
        }
    }

Solution

    1. Make sure the jar is actually in the build path (if I knew your IDE I might have given more concrete instructions).
    2. If this doesn't solve the problem, search these classes and methods in that jar. If they're there - try to perform step 1 above better... If it's not there - then you have the wrong jar.