Cannot resolve method java ошибка

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.

Cœur's user avatar

Cœur

36.9k25 gold badges193 silver badges262 bronze badges

asked Jan 6, 2011 at 19:13

Landon Kuhn's user avatar

Landon KuhnLandon Kuhn

75.9k45 gold badges103 silver badges130 bronze badges

2

Most likely JDK configuration is not valid, try to remove and add the JDK again as I’ve described in the related question here.

Community's user avatar

answered Jan 6, 2011 at 19:20

CrazyCoder's user avatar

CrazyCoderCrazyCoder

386k170 gold badges980 silver badges894 bronze badges

1

First check if you have configured JDK correctly:

  • Go to File->Project Structure -> SDKs
  • your JDK home path should be something like this:
    /Library/Java/JavaVirtualMachine/jdk.1.7.0_79.jdk/Contents/Home
  • Hit Apply and then OK

Secondly check if you have provided in path in Library’s section

  • Go to File->Project Structure -> Libraries
  • Hit the + button
  • Add the path to your src folder
  • Hit Apply and then OK

This should fix the problem

answered Sep 28, 2015 at 3:03

user4660857's user avatar

3

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.

enter image description here

Next, I Removed project from IntelliJ and delete all IntelliJ and IDE related files and folder from the project folder (.idea, .settings, .classpath, dependency-reduced-pom). Also, delete the target folder and re-import the project.

The above solution worked in my case.

answered Aug 21, 2020 at 5:24

Maulik Kakadiya's user avatar

Maulik KakadiyaMaulik Kakadiya

1,4551 gold badge21 silver badges31 bronze badges

1

For me, I had to remove the intellij internal sdk and started to use my local sdk. When I started to use the internal, the error was gone.

my sdks

answered Feb 27, 2021 at 21:19

Thiago Cavalcanti's user avatar

I tried almost everything but nothing was helping with the ibm jdk 1.8. to fix this issue. then I found an article from https://youtrack.jetbrains.com/issue/IDEA-279214/Cannot-resolve-symbol-String-when-using-IBM-JDK-180 and it worked like charm!!!

so sharing original help credit goes to @Serge Barano. incase anybody needs and not able to able to resolve the issue using previous solutions like me.

according to the article answer is:

IBM JDK has a weird layout and the jar with the String class is in bin directory for some reason:

d:devibm_sdk80jrebindefaultjclSC180vm.jar

If you add it to the JDK classpath in IntelliJ IDEA, the issue should resolve:
enter image description here

answered Jun 1, 2022 at 19:56

Priyanka Wagh's user avatar

Priyanka WaghPriyanka Wagh

5951 gold badge7 silver badges17 bronze badges

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.

answered Jul 6, 2017 at 2:03

Darien's user avatar

DarienDarien

3,45219 silver badges35 bronze badges

First of all you should try File | Invalidate Caches and if it doesn’t help, delete IDEA system directory. Then re-import the Maven project and see if it helps.

answered Aug 12, 2021 at 11:16

sarjeet singh's user avatar

For me ,

File -> project structure -> Project Language Level (11) selection worked. Local variable syntax for lambda paramters.

answered Oct 18, 2021 at 9:42

Rishabh Dugar's user avatar

In my case, cloning repo from the remote was the easiest way to solve this issue.

answered Apr 27, 2022 at 18:14

Temur Isroilov's user avatar

In my case, right click on String then choose «Show Context Actions», it will give you option to Setup JDK, then click always downloaded. Then the error will be gone.
enter image description here

answered May 4 at 2:06

Yibingqing Jiang's user avatar

Не могу понять почему не может реализовать метод

robotFirst.getName(), robotSecond.getName(),

метод getName не работает!

public static void doMove(AbstractRobot robotFirst, AbstractRobot robotSecond) {
        BodyPart attacked = robotFirst.attack();
        BodyPart defenced = robotFirst.defense();
        System.out.println(String.format("%s атаковал робота %s, атакована %s, защищена %s",
                robotFirst.getName(), robotSecond.getName(), attacked, defenced));
    }
}

Я так понимаю что мы обращаемся к объекту РОБОТУ (например robotFirst )и вызываем у него метод возвращения имени, но он почему то не работает.

Задача ‘Friends&Family’
В строке с методом nextDouble () и nextInt (), выдаёт ошибку…
5de65f093ef54905035008.jpeg

причём в разжовывании работы с сканером:
5de65f303bc69406092347.jpeg
всё работет норм.

Дело в — do?! Но нет! Я вставил пример из пояснения и он выдал ту же ошибку! У меня явно чего-то не хватает в идее!

*одно хорошо, пока курил, много интересного прочёл…
** работают jdk1.8.0_231 и java jre1.8.0_231

Lombok is a library that reduces boilerplate code when using the Java programming language. In comparison with modern script languages such as Python or Ruby, Java tends to be overly verbose: In order to create a class with a few attributes serving as a data object, one needs to create numerous getters and setters as well as custom equals and hashCode implementations. Of course, the Java IDE landscape has reacted to this kind of problem a long time ago by equipping IDE users with several ways to generate these methods on demand.

However, maintaining such data classes can still be hassle: Just imagine a programmer quickly adding one or more attributes to a data class because a new feature needs to be implemented that relies on those. They surely will remember to generate the getters and setters because otherwise they won’t be able to access the new attributes. They might miss to update the toString method or the equals and hashCode methods, though, and what gives? All tests might pass and everything could be fine for a while. But then a bug is discovered that either might be related to the equals method not reflecting the newly added attributes that could potentially lead to overwriting data entities in collections or a crucial log message does not give a programmer the values of the added attributes because the toString method has not been updated.

Lombok deals with these problems by generating getters, setters, constructors, useful toString methods as well as equals and hashCode implementations in the build process of your app. Integrating Lombok, say, in a Gradle build, is as easy as adding

compileOnly 'org.projectlombok:lombok'

to the dependencies of your build.gradle file. Afterwards, a data class may be written as follows:

import lombok.*;

@Data
@NoArgsConstructor
@RequiredArgsConstructor
class Account {
  private @NonNull String accNumber;
  private double saldo;
}

The annotation @Data gives you getters and setters for all attributes of your class as well as a toString, a hashCode and an equals implementation. The annotations @NoArgsConstructor and @RequiredArgsConstructor give you the standard constructor as well as a constructor with all the required fields (in this case, all fields annotated as @NonNull).

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and
privacy statement. We’ll occasionally send you account related emails.

Already on GitHub?
Sign in
to your account

Comments

@oleksandrzaiats

After fix for #778 issue I have got an error in IDE.
I am using new version of lombok with the fix (1.16.16) and Java 8.
It turns whole my project to red with hint that IDE Cannot resolve method 'onMethod_' (I am using Intellij).
But compilation is successful and generated code is working as expected.

public class DTO {
	@Getter(onMethod_= @TestAnnotation(testParam = "testParam"))
	@Setter
	String data;
}

Actually there is not such method in sources https://github.com/rzwitserloot/lombok/blob/master/src/core/lombok/Getter.java, only AnyAnnotation[] onMethod() default {};
I don’t want to disable Cannot resolve method Intellij inspection, is there any way to fix it?

@ikstewa

@Maaartinus

Actually there is not such method in sources

AFAIK, it mustn’t exist.

https://projectlombok.org/features/experimental/onX.html

The syntax is a little strange and depends on the javac you are using.
On javac7, to use any of the 3 onX features, you must wrap the annotations to be applied to the constructor / method / parameter in @__(@AnnotationGoesHere)….
On javac8 and up, you add an underscore after onMethod, onParam, or onConstructor.

@denbypda

Getting the same issue when using new Java8 onMethod syntax with Windows jdk1.8.0_121 and lombok 1.16.16.

Using the new JDK 8 syntax

@Getter(onMethod_ = { @JsonProperty(value = ID) })

No IDE, just javac

error: cannot find symbol
@getter(onMethod_ = { @JsonProperty(value = ID) })
^
symbol: method onMethod_()
location: @interface Getter

@vguna

Same here, exact same version.

@evgenyh

facing the same
any solution for this ?

@roglar

I run into this when upgrading to java8 but not another person in my team!
After comparison we found out that compiler arg caused this (in maven)

javac -processor org.checkerframework.checker.nullness.NullnessChecker …

Without this even the java7 method compiles, will delombok getters and setters that needed this…

@LilithBristol

Same here

JDK:9.0.4
idea: 2018.1
lombok:1.16.20

can some one help?

@ronnyfm

Facing a similar issue when I run Enunciate plugin. Eclipse works after I run the Lombok JAR, and the Maven project compiles without errors, but other IDEs (like Visual Studio Code) and moreover, the Enunciate plugin is unable to finish.

@ronnyfm

I run into this when upgrading to java8 but not another person in my team!
After comparison we found out that compiler arg caused this (in maven)

javac -processor org.checkerframework.checker.nullness.NullnessChecker …

Without this even the java7 method compiles, will delombok getters and setters that needed this…

Do you mean to add that parameter or to remove it in order to compile? I was trying to add the parameter in the Maven configuration but it is not working.

@oleksandrzaiats

Понравилась статья? Поделить с друзьями:
  • Cannot receive hello packet miflash ошибка edl
  • Cannot receive hello packet miflash ошибка 4pda
  • Cannot read properties of undefined честный знак ошибка
  • Cannot read properties of undefined reading map ошибка
  • Cannot read properties of undefined reading length ошибка