The compilation error occurs because you're extending Activity
and not PreferenceActivity
.
So replace
public class MainActivity extends Activity {
with
public class MainActivity extends PreferenceActivity {
and you should be good to go.