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 Exploring the Master-Detail Template Blog Reader Project Overview

Declaring the Strings as private returns compile error

There shouldn't be a compile error on "private String".

private String title1 = "Android is awesome";
private String title2 = "Mike is cool";
private String title3 = "Treehouse loves me";

The code above returns a compile error.

String title1 = "Android is awesome";
String title2 = "Mike is cool";
String title3 = "Treehouse loves me";

This code compiles fine and lets me continue to the next question.

4 Answers

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

You can only use access modifiers like private at the class level. This particular code challenge is just simple Java code that runs in the context of our Code Challenge engine test methods. I can understand your confusion. :)

public class Dog {
    private String mName = "Shoogie";  // valid use of private

    public void bark() {
        private String bark = "woof"; // Invalid! The variable is in the scope of the method.
                                      // It's not at the class level.
    }
}
Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

Can you paste your whole code? There must be something else triggering the error.

Updated original post.

Oh, it was actually inside a method, like a main method, I see now. Thanks for explaining that for me Ben.