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 Rebuilding from Scratch Adding Data for the List

Kim Timotius
Kim Timotius
2,938 Points

Error in Build a Blog Reader App Code Challenge: Adding Data for the List

I got an error on the first task of the Adding Data for the List code challenge.

The question: Declare an array of Strings as a member variable of the MainListActivity class. Name it 'mSongTitles', make it 'public', and initialize it with at least three values.

My answer: public String[] mSongTitles = { "Song1", "Song2", "Song3", "Song4" };

The error: Bummer! There is a compiler error. Please click on preview to view your syntax errors!

When I click on preview button: /srv/code_challenges/releases/20140901132830/lib/challenge_engine/runners/>includes/java/android/widget/ArrayAdapter.java:6: error while writing >android.widget.ArrayAdapter: /srv/code_challenges/releases/20140901132830/lib/challenge_engine/runners/>includes/java/android/widget/ArrayAdapter.class (Permission denied) public class ArrayAdapter extends BaseAdapter { ^ 1 error

What have I done wrong?

2 Answers

Doug Ray
Doug Ray
7,493 Points

Hey Timotius

Your declaration looks fine the only thing may be that your not declaring it as a member variable of the class, for example placing the declaration inside the class makes it a member variable because it is now visible to all members of this class.

public class MainListActivity extends ListActivity {

public String[] mSongTitles = { "Song1", "Song2", "Song3", "Song4" };

}

Kim Timotius
Kim Timotius
2,938 Points

Yes I did declare it inside the MainListActivity class. There is nothing wrong with the code. It seems there was something wrong with Treehouse system that time because I tried the code challenge again with the same code this time and it works. Thanks for your help anyway Doug Ray.

Doug Ray
Doug Ray
7,493 Points

Awesome glad its up and working for you again ! =D.

I also had "challenge analyzer" trouble with the "Adding Data to the List" for the Blog Reader: http://teamtreehouse.com/library/build-a-blog-reader-android-app/rebuilding-from-scratch/adding-data-for-the-list

The code wouldn't past but after

**** multiple pastings of the same code ****

I finally got through all three parts of the challenge with this code:

package com.example;

import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;

public class MainListActivity extends ListActivity {

  public String[] mSongTitles = { "Song1", "Song2", "Song3", "Song4" };

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main_list);
      ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,mSongTitles);
      setListAdapter(adapter);
    }
}