2013-01-09 106 views
1

我想創建首選項活動,但出現以下錯誤。Android首選項活動 - R無法解析爲變量

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> 
+0

關於此問題有很多現存問題。你看過他們的解決方案嗎? http://stackoverflow.com/search?q=%5Bandroid%5D+r+cannot+be+resolved+to+a+variable – CloudyMusic

+0

@cloudymusic yesh我做到了。我只在偏好活動中獲得此信息,因此發佈了一個問題 –

回答

3

清理項目,然後再試一次,否則嘗試

import package.name.R 
0

我花了很多小時尋找這個相同的答案。 import com.package.name.R;是最終解決它的。感謝您的幫助。