Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Android Android Activity Lifecycle Introducing SharedPreferences Saving and Retrieving Data with SharedPreferences

Error while doing Android activity lifecycle code challenge

Challenge 1: We'd like to persist the value of a CheckBox by using SharedPreferences. Start by declaring a constant for the file name of our preferences called PREFS_FILE. Then declare a constant for the key we'll require; call it KEY_CHECKBOX.

I am most likely confident that my answer is correct. But there is a compiler error.

MainActivity.java
import android.view.View;
import android.os.Bundle;

public class MainActivity extends Activity {

  public CheckBox mCheckBox;
  private static final String PREFS_FILE = "com.teamtreehouse.sharedpreferencesapp.preferences";
  private static final String KEY_CHECKBOX = "KEY_CHECKBOX";

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mCheckBox = (CheckBox) findViewById(R.id.checkBox);
  }
}

This is the compiler error

JavaTester.java:65: error: illegal start of expression import android.view.View; ^ JavaTester.java:65: error: not a statement import android.view.View; ^ JavaTester.java:66: error: illegal start of expression import android.os.Bundle; ^ JavaTester.java:66: error: not a statement import android.os.Bundle; ^ JavaTester.java:68: error: illegal start of expression public class MainActivity extends Activity { ^ 5 errors