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 trialRicky Sparks
22,249 PointsJAVA 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
Gunjeet Hattar
14,483 PointsHi 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
2,286 PointsHi, 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
Gunjeet Hattar
14,483 PointsYou'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
2,286 PointsAhhh I see, they look exactly the same!
Many thanks
Phillip Hurst
4,204 Pointsthanks, I did the same thing: writing the number 1 instead of the lower case letter L.