views:

45

answers:

1

Hi guys,

I'm experimenting with twitter4j on android (new to both) coded up a simple process in java just to test it out. It downloads a users timeline and prints to screen.

I modify the code for android, but I get a TwitterException when i try to download the user timeline. I checked out the debugger and the exception is null; no information given. I've also added the Internet permission to the android manifest on previous advice. Heres the code:

package com.test;

import java.util.List;


import twitter4j.Status;
import twitter4j.Twitter;
import twitter4j.TwitterException;
import twitter4j.TwitterFactory;
import android.app.Activity;
import android.os.Bundle;

public class Test2 extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        List<Status> statuses = null;
        Twitter api = new TwitterFactory().getInstance("USERNAME","PASSWORD");

        try{
         statuses = api.getUserTimeline();
        }
        catch(TwitterException e){
            System.out.println("ERROR");
            System.exit(-1);
        }
        for(Status s: statuses){
            System.out.println(s.getText());
        }
    }
}

I realise this only prints to the console, just to keep it simple.

Thanks for any and all help.

+1  A: 

Make sure you have the INTERNET permission in your AndroidManifest.xml file.

Also System.out.println() is not recommended on Android. Please use the android.util.Log class and send your debugging output to LogCat (available via adb logcat, DDMS, or the DDMS perspective in Eclipse).

CommonsWare