1

我正在尝试创建首选项活动,但出现以下错误。

R cannot be resolved to a variable

SettingsPreference.java

package com.m7.nomad.preferences;

import android.os.Bundle;
import android.preference.PreferenceActivity;

public class SettingsPreference extends PreferenceActivity  {


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.preferences_settings);
    }
}

res/xml/preferences_settings.xml

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >

    <PreferenceScreen
        android:key="settingsPrefScreen"
        android:title="Account Settings" >
        <Preference
            android:key="profilePref"
            android:title="Your Profile" />
        <Preference
            android:key="passwordPref"
            android:title="Change Password" />
        <Preference
            android:key="privacyPref"
            android:title="Privacy Settings" />
    </PreferenceScreen>

    <Preference
        android:key="notificationPref"
        android:title="Notification Settings" />
    <Preference
        android:key="socialPref"
        android:summary="Facebook, Foursquare, Twitter"
        android:title="Social Connect" />

    <PreferenceCategory android:title="Device Settings" >
        <CheckBoxPreference
            android:defaultValue="true"
            android:key="pushPref"
            android:summary="Show on status bar when new notifications are recieved"
            android:title="Push Notifications" />
        <CheckBoxPreference
            android:defaultValue="true"
            android:dependency="pushPref"
            android:key="vibratePref"
            android:summary="Vibrate on incoming notifications"
            android:title="Vibrate" />
        <CheckBoxPreference
            android:defaultValue="true"
            android:dependency="pushPref"
            android:key="lightPref"
            android:summary="Pulse light for notification"
            android:title="Notification Light" />
    </PreferenceCategory>
    <PreferenceCategory android:title="Friends" >
        <Preference
            android:key="addFriendsPref"
            android:summary="Find friends on Bakasura"
            android:title="Add friends" />
        <Preference
            android:key="friendReqPref"
            android:summary="Approve pending friend requests"
            android:title="Friend  Requests" />
    </PreferenceCategory>
    <PreferenceCategory android:title="Troubleshooting" >
        <Preference
            android:key="helpPref"
            android:summary="Get help using Bakasura!"
            android:title="Help" />
        <Preference
            android:key="reportPref"
            android:summary="Send a force-close report by email"
            android:title="Send report" />
        <Preference
            android:key="cachePref"
            android:summary="sdfas"
            android:title="asdsa" />
    </PreferenceCategory>
    <PreferenceCategory android:title="About" >
        <PreferenceScreen
            android:key="aboutPrefScreen"
            android:summary="About, Terms of Service, Privacy Policy"
            android:title="About" >
            <Preference
                android:key="versionPref"
                android:summary="sadsa"
                android:title="Version" />

            <PreferenceCategory android:title="Legal" >
                <Preference
                    android:key="tosPref"
                    android:title="Terms of Service" />
                <Preference
                    android:key="privacyPolicyPref"
                    android:title="Privacy Policy" />
            </PreferenceCategory>
        </PreferenceScreen>
    </PreferenceCategory>
</PreferenceScreen>
4

2 回答 2

3

清理项目重试,否则再试

import package.name.R
于 2013-01-09T17:26:26.120 回答
0

我花了很多时间寻找同样的答案。导入 com.package.name.R; 是什么最终修复它。感谢您对此的帮助。

于 2013-04-07T04:14:54.640 回答