0

I have a problem in my code that says : can not convert from element type object to status. I tried all the solution that proposed previously but I could not find one that match my statement. Can you please help to configure the problem and get the solution please?

This is my code. It basically about getting tweets more than 100, and split it for data mining purpose.

List statuses = new ArrayList();

            while (true) {

              try {

                int size = statuses.size(); 
                Paging page = new Paging(pageno++, 100);
                statuses.addAll(twitter.getUserTimeline(user, page));
                if (statuses.size() == size)


                  break;


              }
              catch(TwitterException e) {

                e.printStackTrace();
              }


              for(Status status2 : statuses){
                        status2.getText();
                                //System.out.println(status2.getCreatedAt());

                                String s = status2.getText();
                                String[] splitted = s.split(" ");
                                //System.out.println(s);
                                for(String str : splitted){
                                    //System.out.println(str);

                                    if(doesListContainWord(str)){
                                        incrementKeyofWordInList(str);
                                    }else{
                                        if(doesWordCountAsAWord(str)){
                                            addNewWordToList(str);
                                        }
                                    }
MSU_Bulldog
  • 3,501
  • 5
  • 37
  • 73
Afnan Humdan
  • 195
  • 3
  • 12

2 Answers2

1

Change List statuses = new ArrayList(); to List<Status> statuses = new ArrayList<Status>(); as you need to infer to the generic type (type of the list or the type of objects that the list is going to store)

Harsh Poddar
  • 2,394
  • 18
  • 17
0

First of all this definition:

List statuses = new ArrayList();

Is equivalent to:

List<Object> statuses = new ArrayList<Object>();

If instead you use

List<Status> statuses = new ArrayList<Status>();

The for loop Java 7 style will return a Status object instead of a plain object. So for(Status status2 : statuses){ will work.

JFPicard
  • 5,029
  • 3
  • 19
  • 43