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 trialHu Shien Tan
29,650 PointsError 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.
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