setListAdapter within MainActivity

Hi I'm trying to get my listview to work with json and in my MainActivity. I have an error on my onPostExecute(string result) method. It gives me the following error: "The method setListAdapter(CustomAdapter) is undefined for the type MainActivity.getTweets". I have the following:

public class Main Activity extends Activity {
    ArrayList<TweetDetailClass> tweets = new ArrayList<TweetDetailClass>();

    protected void onCreate(Bundle savedInstanceState) { .. }

    public boolean onCreateOptionsMenu(Menu menu) { .. }

    public void searchTwitter(View view){
        new GetTweets().execute(searchURL);

    public class GetTweets extends AsyncTask<String, Void, String>{
        protected String doInBackground(String... twitterURL){ .. }
        protected void onPostExecute(String result) {
             setListAdapter(new CustomAdapter(MainActivity.this, R.layout.listview, tweets));

CustomAdapter Constructor

CustomAdapter(Context c, int textView, ArrayList<TweetDetailClass> data){
    //_data = data;
    //_c = c;
    super(c, textView, data);
    this._data = data;

Thanks for your help! I'm a beginner so any help would be greatly appreciated!


setListAdapter() can only be used if your Activity extends ListActivity and I think your xml layout must contain a ListView object with the id "@android:id/list".

Alternativelly, if your Activity extends Activity you should set the adapter like:

yourListView.setAdapter(new CustomAdapter(MainActivity.this, R.layout.listview, tweets));

Let me know if it helps!

setListAdapter() is a method on ListActivity. Your activity (whose name apparently is the invalid Main Activity) appears to inherit from Activity, not ListActivity.

Need Your Help

Integration-Manager Git Workflow using Jenkins/Hudson

eclipse git hudson jenkins junit4

I'm trying to implement a modified Integration-Manager workflow similar to what's described in ProGit.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.