2011-01-21 12 views
19

मेरे एप्लिकेशन@Override एनोटेशन त्रुटि (एंड्रॉयड वरीयता)

import android.app.Activity; 
import android.content.SharedPreferences; 
import android.os.Bundle; 
import android.preference.Preference; 
import android.preference.PreferenceActivity; 
import android.preference.Preference.OnPreferenceClickListener; 
import android.widget.CheckBox; 
import android.widget.CompoundButton; 
import android.widget.RadioButton; 
import android.widget.Toast; 
import android.widget.CompoundButton.OnCheckedChangeListener; 


public class Preferences extends PreferenceActivity { 

private RadioButton btn01; 
@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    addPreferencesFromResource(R.xml.preferences); 
    btn01 = (RadioButton)findViewById(R.id.RadioButton01); 
    Preference customPref = (Preference) findPreference("customPref"); 

    customPref.setOnPreferenceClickListener(new OnPreferenceClickListener(){ 

     public boolean onPreferenceClick(Preference preference) { 
      Toast.makeText(getBaseContext(),"The Custom Preference Has Been Clicked",Toast.LENGTH_LONG).show(); 
      SharedPreferences customSharedPreference = getSharedPreferences("myCutomSharedPrefs", Activity.MODE_PRIVATE); 
      SharedPreferences.Editor editor = customSharedPreference.edit(); 
      editor.putString("myCustomPref","The preference has been clicked"); 
      editor.commit(); 
      return true; 
     } 


     public void CheckBox() { 
      final CheckBox ThisCheckBox = (CheckBox) findViewById (R.id.checkboxPref); 
      ThisCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener(){ 
       @Override 
       public void onCheckedChanged(CompoundButton compoundButton,boolean test) { 
        if (ThisCheckBox.isChecked()){ 
         btn01.setVisibility(0); 
        } else { 
         btn01.setVisibility(2); 
        } 
       } 
      }); 
     }; 
    }); 
} 
} 

कोई त्रुटि इस लाइन

public void onCheckedChanged(CompoundButton compoundButton,boolean test) { 

कह पर उत्पन्न होता है में वरीयताओं सक्षम करने के लिए इस कोड का उपयोग करने के लिए कोशिश कर रहा था:

Multiple markers at this line 
- The method onCheckedChanged(CompoundButton, boolean) of type new 
CompoundButton.OnCheckedChangeListener(){} must override a superclass method 
- implements 
android.widget.CompoundButton.OnCheckedChangeListener.onCheckedChanged 

अगर मैं @ ओवरराइड एनोटेशन हटा देता हूं तो कोड काम नहीं करता है और एक चेतावनी मुझे बताती है कि उस हिस्से का कोड स्थानीय रूप से उपयोग नहीं किया जाता है।

इस पिछले किसी को चलाने और उन्हें परेशान करने के बाद मैं सोच रहा था कि क्या आप मदद कर सकते हैं?

क्या कोई सामान्य परिदृश्य है जो इस त्रुटि का कारण बनता है?

मैं इसे अपने परियोजना

धन्यवाद

उत्तर

18

यह एक कार्यान्वयन बात है स्थापित किया जा सकता है सोचा। जावा 5 बनाम जावा 6 में उन्होंने बदल दिया है कि क्या आप इंटरफ़ेस के साथ "ओवरराइड" का उपयोग कर सकते हैं (क्योंकि ओवरराइड का अर्थ यह है कि आप किसी प्रकार का डिफ़ॉल्ट व्यवहार ओवरराइड कर रहे हैं, जिसे आप इंटरफेस के साथ नहीं कर रहे हैं!)। यदि आप चाहें, तो आप ग्रहण वरीयताओं में खोज सकते हैं और इसे संकलन त्रुटि से संकलन चेतावनी में बदल सकते हैं। आप चेकबॉक्स() फ़ंक्शन के अंदर कोड मुझे ठीक लगते हैं।

हालांकि, आप कभी भी चेकबॉक्स फ़ंक्शन को कॉल नहीं कर रहे हैं, इसलिए वह जगह है जहां 'स्थानीय रूप से उपयोग नहीं किया गया' त्रुटि आ रही है। क्या आप उस फ़ंक्शन को OnPreferenceClick विधि के भीतर से कॉल करना चाहते थे?

+0

वाह आदमी! बहुत बहुत धन्यवाद। ठीक है तो अगर मैं स्थानीय रूप से उपयोग किया जाता है तो चेकबॉक्स विधि को कैसे और कहां कॉल करूँ? – Jack

+0

ऑनपेरेंसक्लिक विधि के अंदर से ऐसा करने का एक तरीका है। Editor.commit() के बाद चेकबॉक्स() पर एक कॉल जोड़ें; – Hamy

+4

बस अपने YourProject-> राइटक्लिक-> गुण-> जावा कंपाइलर-> 1.5, 1.6 में 1.5 से 1.6 संशोधित करें। आवेदन करें और पुनर्निर्माण के लिए हाँ। – Siddharth

49

आप परियोजना सेटिंग्स -> जावा कंपाइलर पर जा सकते हैं, और संकलक अनुपालन स्तर 1.6 पर स्विच कर सकते हैं। जब भी मैं एक मौजूदा परियोजना आयात करता हूं तो मुझे इसे करना होगा।

+0

हाँ, यह मेरे लिए काम करता है। – anticafe

+0

मैंने 'कंपाइलर अनुपालन 1.5 से 1.6 तक बदल दिया और यह काम किया। धन्यवाद –

5

सिर्फ साझा करना चाहता था, मैंने यहां मिली जानकारी के आधार पर एक पोस्ट लिखा था। मुझे आशा है कि यह सहायक होगा!

http://qtcstation.com/2011/05/android-and-jdk-compliance/

+1

लिंक के लिए धन्यवाद। ग्राफिक्स सहायक थे। – Ahmed

संबंधित मुद्दे