Android Studio cannot resolve symbol but code executes correctly
EDIT: For most folks, Senthil's answer will be more appropriate. I am leaving this one as the accepted answer because it solved my specific problem.
I found the issue - my SDK.jar
was not generated correctly. It included .java
files instead of .class
files. This explains why the IDE was not able to find the SDK class. The package structure was still correct in the Jar, which is why the package name itself is not a red color. The code worked correctly, because the compiler knew to compile the .java
files.
To solve the issue, I modified my build.gradle
of my SDK project to include .class
files, instead of .java
files, when creating the Jar. Including this new Jar instead of the old Jar fixed the IDE issue.
Android Studio says cannot resolve symbol but project compiles
No idea if this will work or not but my only thought so far: right click the jar file in file tree within AS and select "Add as library..."
EDIT: You can do "File" -> "Invalidate Caches...", and select "Invalidate and Restart" option to fix this.
EDIT 2: This fix should work for all similar incidents and is not a twitter4j specific resolution.
Android Studio “cannot resolve symbol R” but project compiles and runs
For some reason that i do not understand ,
this combination of build versions made the issue :
grade version = 4.10.1
classpath 'com.android.tools.build:gradle:3.4.0-alpha01'
when i switched to these build versions :
grade version = 4.6
classpath 'com.android.tools.build:gradle:3.2.1'
The issue was solved !
Android Studio suddenly cannot resolve symbols
You've already gone down the list of most things that would be helpful, but you could try:
- Exit Android Studio
- Back up your project
- Delete all the .iml files and the .idea folder
- Relaunch Android Studio and reimport your project
By the way, the error messages you see in the Project Structure dialog are bogus for the most part.
UPDATE:
Android Studio 0.4.3 is available in the canary update channel, and should hopefully solve most of these issues. There may be some lingering problems; if you see them in 0.4.3, let us know, and try to give us a reliable set of steps to reproduce so we can ensure we've taken care of all code paths.
Source Code File Cannot resolve symbol 'R'
Close the project. Delete .gradle , .idea folders of the project and then reopen the project. and then try a fresh re-build and then you're good to go.
Else try invalidate caches and restart.
Related Topics
Getting Jsoup to Support Dynamically Generated HTML by JavaScript
Remove Padding/Margin from Javafx Label
How to Use Jsp/Jstl to Generate Dynamic CSS/JavaScript Files
Unobtrusive Way to Combine and Compress JavaScript/CSS for Java/Spring/Maven Applications
How to Clear the (Css) Visited History of an Android Webview
Selenium Webdriver - Getcssvalue() Method
Dynamically Add CSS Stylesheets in Javafx
How to Set -Fx-Max-Width to Use_Pref_Size in Javafx CSS
How to Get the Selected Index of a Radiogroup in Android
How to Set Background Color of an Activity to White Programmatically
How to Manage Cookies with Httpclient in Android And/Or Java
Getextractedtext on Inactive Inputconnection Warning on Android
Getting Java Gui to Open a Webpage in Web Browser
How to Populate a Drop Down with a List Using Thymeleaf and Spring
How to Fill Data in a Jtable with Database
Difference Between Actionbarsherlock and Actionbar Compatibility