Android Studio says that “method cannot be resolved”, but the method exists and compiles

I am trying to debug the behavior of Android Studio regarding syntax highlighting and definition for files in the java SDK folder. The project is built perfectly, but Android Studio itself will not match this in the editor.

I read the answers in detail in the following link and did not fix the problem: Android Studio says that "cannot resolve the character" but compiles the project

I tried all these solutions, including "Invalidate and Restart", "Clean", "Restore", check the sdk directory correctly, check for all dependencies, repeat gradle synchronization, change compileSdkVersion to minSdkVersion and still refuse to follow the expected behavior.

Android Studio highlights some methods and symbols in red and will not follow them when I click on them CTRL + B (go to the definition). However, when I just open the file, the methods and symbols are fine there.

For example, for sdk\sources\android-14\...the RingtonePreference class in ...android\preference\RingtonePreference.javathere is a line:

PreferenceFragment owningFragment = getPreferenceManager().getFragment();

The method is getFragment()highlighted in red for the parameter "cannot resolve the method."

Then I press CTRL + B on getPreferenceManager(), which jumps to:

public PreferenceManager getPreferenceManager() {
    return mPreferenceManager;
}

CTRL + B PreferenceManager, ...android\preference\PreferenceManager.java. :

PreferenceFragment getFragment() {
    return mFragment;
}

, , , Android Studio , . ?

, , RingtoneManager, " " Android Studio:

import android.content.Context;
import android.content.Intent;
import android.media.RingtoneManager;
import android.net.Uri;
import android.preference.RingtonePreference;
import android.util.AttributeSet;

public class ExtRingtonePreference extends RingtonePreference {
private String mInitialRingtone;

public ExtRingtonePreference(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
}

public ExtRingtonePreference(Context context, AttributeSet attrs) {
    super(context, attrs);
}

public ExtRingtonePreference(Context context) {
    super(context);
}

@Override
protected Uri onRestoreRingtone() {
    if(mInitialRingtone == null) {
        return null;
    } else {
        return Uri.parse(mInitialRingtone);
    }
}

public void setInitialRingtone(String initialRingtone) {
    this.mInitialRingtone = initialRingtone;
}

}
+4
1

git, , app/build.gradle (, ), IDE Sync * * .

+1

Source: https://habr.com/ru/post/1673570/


All Articles