• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps cannon add a launch intent to an onItemclick in async task

Basically I have an async task that runs to populate a listView. When I try and set the onitemclick for the listView to launch a new activity I can not:

[HIGH]public class GetBreweryStatisticsJSON extends AsyncTask
<String, Void, String> {

Context c;

public GetBreweryStatisticsJSON(Context context)
c = context;

protected String doInBackground(String... arg0) {
// TODO Auto-generated method stub
return readJSONFeed(arg0[0]);

protected void onPostExecute(String result){
//decode json here
JSONArray jsonArray = new JSONArray(result);

//acces listview
ListView lv = (ListView) ((Activity) c).findViewById(R.id.yourBreweryStatistics);

//make array list for beer
final List<BreweryInfo> tasteList = new ArrayList<BreweryInfo>();

for(int i = 0; i < jsonArray.length(); i++) {

String brewery = jsonArray.getJSONObject(i).getString("brewery");
String rate = jsonArray.getJSONObject(i).getString("rate");
String breweryID = jsonArray.getJSONObject(i).getString("id");

int count = i + 1;

brewery = count + ". " + brewery;

Log.d("brewery stats" , brewery);

//create object
BreweryInfo tempTaste = new BreweryInfo(brewery, breweryID, rate);

//add to arraylist

//add items to listview
BreweryInfoAdapter adapter1 = new BreweryInfoAdapter(c ,R.layout.brewer_stats_listview, tasteList);

//set up clicks
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
BreweryInfo o=(BreweryInfo)arg0.getItemAtPosition(arg2);

String bID = o.breweryID;

Intent i = new Intent(c, BreweryPage2.class);
i.putExtra("beerID", bID);



catch(Exception e){



public String readJSONFeed(String URL) {
StringBuilder stringBuilder = new StringBuilder();
HttpClient httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(URL);
try {
HttpResponse response = httpClient.execute(httpGet);
StatusLine statusLine = response.getStatusLine();
int statusCode = statusLine.getStatusCode();
if (statusCode == 200) {
HttpEntity entity = response.getEntity();
InputStream inputStream = entity.getContent();
BufferedReader reader = new BufferedReader(
new InputStreamReader(inputStream));
String line;
while ((line = reader.readLine()) != null) {
} else {
Log.d("JSON", "Failed to download file");
} catch (Exception e) {
Log.d("readJSONFeed", e.getLocalizedMessage());
return stringBuilder.toString();


It keeps saying:

The method startActivity(Intent) is undefined for the type new AdapterView.OnItemClickListener(){}


We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.