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

Android Build a Blog Reader Android App Using Intents to Display and Share Posts Opening a Webpage in the Browser

Ricky Sparks
Ricky Sparks
22,249 Points

JAVA Code wont pass?

import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.view.View;
import android.view.ListView;
import android.content.Intent;
import android.net.Uri;

public class CustomListActivity extends ListActivity {

    protected String[] mUrls = { "http://www.teamtreehouse.com", "http://developer.android.com", "http://www.github.com" };

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_custom_list);

        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mUrls);
        setListAdapter(adapter);
    }

    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
        // Add code here!
      return inflater.inflate(R.layout.example_fragment, container, false);
    }
}

3 Answers

Hi Ricky,

The challenge says " The 'onListItemClick()' method of our custom Activity has been overridden, but it's empty. Add the first line of code that we normally add when overriding a method from the superclass "

Usually we call the super classes constructor after we override it. Any reason why you added a return statement? This is how it should have been

@Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
        // Add code here!
      super.onListItemClick(l,v,position,id); // call overridden onListItemClick method's superclass constructor

Hope this helps.

Bradley St John Jones
Bradley St John Jones
2,286 Points

Hi, I am having an issue with this challenge. I cannot figure out what I am doing wrong.

import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.view.View;
import android.view.ListView;
import android.content.Intent;
import android.net.Uri;

public class CustomListActivity extends ListActivity {

    protected String[] mUrls = { "http://www.teamtreehouse.com", "http://developer.android.com", "http://www.github.com" };

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_custom_list);

        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mUrls);
        setListAdapter(adapter);
    }

    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
        // Add code here!
    super.onListItemClick(1,v,position,id);
    }
}

The error I get says:

./CustomListActivity.java:24: cannot find symbol
symbol  : method onListItemClick(int,android.view.View,int,long)
location: class ListActivity
    super.onListItemClick(1,v,position,id);
         ^
1 error

Any help would be greatly appreciated as I am pretty certain I am doing this correctly

Cheers

Bradley

You've mistakenly written 1 as in the number one instead of the letter l in your super.onListItemClick

Change it to super.onListItemClick(l,v,position,id);

Bradley St John Jones
Bradley St John Jones
2,286 Points

Ahhh I see, they look exactly the same!

Many thanks

thanks, I did the same thing: writing the number 1 instead of the lower case letter L.