Cannot resolve symbol java что это
Intellij Cannot resolve symbol on import
This problem happens intermittently for different libraries and different projects. When trying to import a library, the package will be recognized, but the class name can’t be resolved.
Please see screen shots:
Anyone have a clue?
29 Answers 29
You can try invalidating the cache and restarting IntelliJ, in many cases it will help.
There can be multiple reasons for this. In my case it was wrong source root issue. Invalidate caches didn’t work along with other solutions.
Check your module source roots.
Project Structure ( Ctrl + Alt + Shift + S ).
Select your problem module.
Change tab on top of window «Sources».
Remove unwanted source roots. Keep one and add src and test source roots in this root.
IntelliJ has issues in resolving the dependencies. Try the following:
Run this command in your project console:
Done. Had this issue many times. Tried ‘Invalidate Cache & Restart’ and all other solutions. Running that command works perfect to me. I’m currently using IntelliJ 2019.2, but this also happened in previous versions and solution worked as well.
Check your module dependencies.
I faced a similar issue, Mike’s comment helped me move in the direction to solve it.
Though the required library was a part of the module in my project too, it needed a change of scope. In the module dependency, I changed the scope to «Compile» rather than «Test» and it works fine for me now.
What worked for my Gradle project was to «Refresh all Gradle projects» from the Gradle tab on top-right corner of IntelliJ v2017, using the yellow marked button shown below:
I found the following answer from @jossef-harush and @matt-leidholm useful from another link
Had the same problem till I noticed that the src folder was marked as root source instead of java! Changing to only the java (src/main/java) to be the source root solved my problem
Right click on pom.xml file, go to Maven click on Reimport. I had similar problem and this worked for me.
After a long search, I discovered that a dependency was somehow corrupted on my machine in a maven project. The strange thing was that the dependency was still working correctly in the compiled java code. When I cleaned and rebuilt my maven dependency cache however, the problem went away and IntelliJ recognized the package. You can do this by running:
Intrestingly, the source of my problem hence wasn’t IntelliJ, but maven itself.
I also got this error for multiple times when I try to build a new java project.
Below is the step how I got this stupid issue.
IntelliJ IDEA «cannot resolve symbol» and «cannot resolve method»
What are common causes for IntelliJ IDEA not being able to resolve built-in JVM types and methods? For example, when I mouse over String the tooltip says «Cannot resolve symbol ‘String'». It’s as if IntelliJ has doesn’t know where the JVM is.
By the way, I am running OS X 10.6.6. Everything was working fine until I ran the system update this morning.
7 Answers 7
Most likely JDK configuration is not valid, try to remove and add the JDK again as I’ve described in the related question here.
First check if you have configured JDK correctly:
Secondly check if you have provided in path in Library’s section
This should fix the problem
For me, IntelliJ could autocomplete packages, but never seemed to admit there were actual classes at any level of the hierarchy. Neither re-choosing the SDK nor re-creating the project seemed to fix it.
What did fix it was to delete the per-user IDEA directory ( in my case
/.IntelliJIdea2017.1/ ) which meant losing all my other customizations. But at least it made the issue go away.
I was facing the same problem when import projects into IntelliJ.
for in my case first, check SDK details and check you have configured JDK correctly or not.
Go to File-> Project Structure-> platform Settings-> SDKs
Check your JDK is correct or not.
Ошибка «Cannot resolve symbol»
выдает ошибку указывает на точку после myterminal
C:\Documents and Settings\вован\Рабочий стол\ЛЕХА 2\integer.java:9: cannot resolve symbol
symbol : method println (java.lang.String,int)
location: class MyTerminalIO
myterminal.println(«Колличество минут в N сутак = «,x);
^
1 error
Tool completed with exit code 1
что здесь не правильно
Проблема с компиляцией: cannot resolve symbol
Скачал и установил jdk1.3.1_06 Добавил в autoexec.bat в Path и SetPath C:/jdk1.3.1_06/bin Если.
Напишите программу на JAVA:которая в строке «а роза упала на лапу азора» находит символ «У» и печатает символы строки до следующего символа «у»
Помогите пожалуйста решить 1) Напишите программу на JAVA:которая в строке «а роза упала на лапу.
Модифицируйте строку так, чтобы все символы «+», предшествующие первой точке, заменяются на символ «-«
Пожалуйста помогите мне сделать задание (Java) Дана строка, в которой содержится хотя бы одна.
C:\Documents and Settings\вован\Рабочий стол\ЛЕХА 2\integer.java:9: cannot resolve symbol
symbol : method println (java.lang.String,int)
location: class MyTerminalIO
myterminal.println(«Колличество минут в N сутак = «,x);
^
правильное написание
C:\Documents and Settings\вован\Рабочий стол\ЛЕХА 2\integer.java:9: cannot resolve symbol
symbol : method println (java.lang.String,int)
location: class MyTerminalIO
myterminal.println(«Колличество минут в N сутак = «+x);
Jsoup, ошибка при подключении » у Вас отключён JavaScript.»
Добрый день. Есть задача распарсить сайт, но возникает проблема при подключения к сайту через.
Ошибка «The operator || is undefined for the argument type(s) boolean, int»
Пытаюсь написать программу которая сообщает какой цвет выпал на рулетке- красный или черный.
What does a «Cannot find symbol» or «Cannot resolve symbol» error mean?
Please explain the following about «Cannot find symbol», «Cannot resolve symbol» or «Symbol not found» errors (in Java):
This question is designed to seed a comprehensive Q&A about these common compilation errors in Java.
16 Answers 16
0. Is there any difference between the two errors?
Not really. «Cannot find symbol», «Cannot resolve symbol» and «Symbol not found» all mean the same thing. Different Java compilers use different phraseology.
1. What does a «Cannot find symbol» error mean?
Your Java source code consists of the following things:
A «Cannot find symbol» error is about the identifiers. When your code is compiled, the compiler needs to work out what each and every identifier in your code means.
A «Cannot find symbol» error means that the compiler cannot do this. Your code appears to be referring to something that the compiler doesn’t understand.
2. What can cause a «Cannot find symbol» error?
As a first order, there is only one cause. The compiler looked in all of the places where the identifier should be defined, and it couldn’t find the definition. This could be caused by a number of things. The common ones are as follows:
For identifiers in general:
For identifiers that should refer to variables:
For identifiers that should be method or field names:
Perhaps you are trying to refer to an inherited method or field that wasn’t declared in the parent / ancestor classes or interfaces.
Perhaps you are mistakenly operating on an array rather than array element; e.g.
For identifiers that should be class names:
Perhaps you forgot to import the class.
Perhaps you used «star» imports, but the class isn’t defined in any of the packages that you imported.
Perhaps you forgot a new as in:
For cases where type or instance doesn’t appear to have the member (e.g. method or field) you were expecting it to have:
Here is an example of how incorrect variable scoping can lead to a «Cannot find symbol» error:
(An appropriate correction here might be to move the if statement inside the loop, or to declare i before the start of the loop.)
Here is an example that causes puzzlement where a typo leads to a seemingly inexplicable «Cannot find symbol» error:
This will give you a compilation error in the println call saying that i cannot be found. But (I hear you say) I did declare it!
Here is another example of «Cannot find symbol» error that is caused by a typo.
In the example I came across, the programmer had actually left out an operator. What he meant to write was this:
Generally speaking, you start out by figuring out what caused the compilation error.
Then you think about what your code is supposed to be saying. Then finally you work out what correction you need to make to your source code to do what you want.
Note that not every «correction» is correct. Consider this:
The point is that you need to understand what your code is trying to do in order to find the right fix.
4. Obscure causes
Incorrect dependencies: If you are using an IDE or a build tool that manages the build path and project dependencies, you may have made a mistake with the dependencies; e.g. left out a dependency, or selected the wrong version. If you are using a build tool (Ant, Maven, Gradle, etc), check the project’s build file. If you are using an IDE, check the project’s build path configuration.
This could happen if the IDE has been configured with the wrong JDK version.
This could happen if the IDE’s caches get out of sync with the file system. There are IDE specific ways to fix that.
This could be an IDE bug. For instance @Joel Costigliola described a scenario where Eclipse did not handle a Maven «test» tree correctly: see this answer. (Apparently that particular bug was been fixed a long time ago.)
Other symbol errors on Android are likely to be due to previously mention reasons; e.g. missing or incorrect dependencies, incorrect package names, method or fields that don’t exist in a particular API version, spelling / typing errors, and so on.
Hiding system classes: I’ve seen cases where the compiler complains that substring is an unknown symbol in something like the following
Lesson: Don’t define your own classes with the same names as common library classes!
The problem can also be solved by using the fully qualified names. For example, in the example above, the programmer could have written:
Homoglyphs: If you use UTF-8 encoding for your source files, it is possible to have identifiers that look the same, but are in fact different because they contain homoglyphs. See this page for more information.
You can avoid this by restricting yourself to ASCII or Latin-1 as the source file encoding, and using Java \uxxxx escapes for other characters.
Android Studio says «cannot resolve symbol» but project compiles
I’m importing twitter4j in AndroidStudio, using the following in my build.gradle:
The project compiles fine, and I can create twitter objects without a problem. However, in Android studio, anything referencing that library shows «cannot resolve symbol» and displays in red. What do I need to do to get Android Studio to recognize the library?
27 Answers 27
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 2: This fix should work for all similar incidents and is not a twitter4j specific resolution.
Try changing the order of dependencies in File > Project Structure > (select your project) > Dependencies.
Invalidate Caches didn’t work for me, but moving my build from the bottom of the list to the top did.
This is what worked for me.
In the Project panel, right click on the project name, and select Open Module Settings from the popup menu.
then change the Compile SDK Version to the minimum version available (the minimum sdk version you set in the project). wait for android studio to load everything.
It will give you some errors, ignore those.
Now go to your java file and android studio will suggest you import
Import it, then go back to Open Module Settings and change the compile sdk version back to what it was before.
Wait for things to load and voila.
For mine was caused by the imported library project, type something in build.gradle and delete it again and press sync now, the error gone.
I also had this issue with my Android app depending on some of my own Android libraries (using Android Studio 3.0 and 3.1.1).
Whenever I updated a lib and go back to the app, triggering a Gradle Sync, Android Studio was not able to detect the code changes I made to the lib. Compilation worked fine, but Android Studio showed red error lines on some code using the lib.
After investigating, I found that it’s because gradle keeps pointing to an old compiled version of my libs. If you go to yourProject/.idea/libraries/ you’ll see a list of xml files that contains the link to the compiled version of your libs. These files starts with Gradle__artifacts_*.xml (where * is the name of your libs).
So in order for Android Studio to take the latest version of your libs, you need to delete these Gradle__artifacts_*.xml files, and Android Studio will regenerate them, pointing to the latest compiled version of your libs.
If you don’t want to do that manually every time you click on «Gradle sync» (who would want to do that. ), you can add this small gradle task in the build.gradle file of your app.
And in order for your app to always execute this task before doing a gradle sync, you just need to go to the Gradle window, then find the «deleteArtifacts» task under yourApp/Tasks/other/, right click on it and select «Execute Before Sync» (see below).
Now, every time you do a Gradle sync, Android Studio will be forced to use the latest version of your libs.