Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Dalton Coble
6,489 PointsError:(27, 9) error: cannot find symbol method setListAdapter(ArrayAdapter<String>)
NEED HELP! Doing Android Blog Reader app. Adding items to list. Error:(27, 9) error: cannot find symbol method setListAdapter(ArrayAdapter<String>) is my error.
package com.example.dalton.blogreader;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ArrayAdapter;
public class MyListActivity extends ActionBarActivity {
protected String[] mAndroidNames = {
"Beat Boy",
"Starfire",
"Raven",
"Cyborg",
"Robin"
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my_list);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,mAndroidNames);
setListAdapter(adapter);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.my_list, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
3 Answers
Dalton Coble
6,489 PointsCan you explain a bit more about how to do that?
Kevin Haube
12,265 PointsHi!
Your class should extend ListActivity for such things as setListAdapter(); to work. :)
Dalton Coble
6,489 PointsI tried this in Android studio and got 6 more errors as well as my first problem.
Kevin Haube
12,265 PointsWhat are the errors telling you, and where are they? :)
Ben Jakuben
Treehouse TeacherThanks, Kevin, for helping in here! Jody, the issues are probably related to import statements after changing to ListActivity. These are some newer issues with backwards compatibility that I will avoid in the upcoming refresh of this project. But if you get past them here you should be good to continue.
Karan Khare
3,477 PointsI have extended my activity to ListActivity for ribbit project but still my app is crashing and when i am just extending it to Activity then setListAdapter is not recognized. and if i am commenting setListAdapter line then my application is running but no value is displayed. Please help i am stuck here from a long time.. Thanks
Ben Jakuben
Treehouse TeacherHi Karan,
Can you paste in details about your error? A screenshot would really help (you can upload it to imgur.com) or any other details about the error.
Kevin Haube
12,265 PointsKevin Haube
12,265 PointsSure thing! :) at the very top, under the
importstatements, change thispublic class MyListActivity extends ActionBarActivityto this
public class MyListActivity extends ListActivityand you should be able to continue from there. :)