IntelliJ: Cannot resolve symbol 'springframework' - java

I'm trying to start my first project with Spring. I use IntelliJ idea and I'm kind of new to it too. But anyways, I followed the step written on the Jetbrains website and I don't know what I have done wrong, but I got a lot of errors on the first to files that are created by default.
BloomBookingApplcation.java
package com.bloombooking;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class BloomBookingApplication {
public static void main(String[] args) {
SpringApplication.run(BloomBookingApplication.class, args);
}
}
Error:(3, 12) Cannot resolve symbol 'springframework'
Error:(4, 12) Cannot resolve symbol 'springframework'
Error:(6, 2) Cannot resolve symbol 'SpringBootApplication'
Warning:(7, 1) Access can be packageLocal
Error:(9, 26) Cannot resolve symbol 'String'
Error:(10, 3) Cannot resolve symbol 'SpringApplication'
Maybe I'm stupid but I don't know which step I've missed...
How can I fix this?
I have found the way to add spring with the quickfix button.
But now I have got new errors I don't understand why... I should maybe download it directly and put the libraries one by one maybe?
Error:(3, 28) Cannot resolve symbol 'boot'
Error:(4, 28) Cannot resolve symbol 'boot'
Error:(6, 2) Cannot resolve symbol 'SpringBootApplication'
Warning:(7, 1) Access can be packageLocal
Error:(9, 26) Cannot resolve symbol 'String'
Error:(10, 3) Cannot resolve symbol 'SpringApplication'
Or maybe it's my IntelliJ idea which isn't configured right since I don't have any completion anywhere and I can't create packages...

Click on refresh button .Maven may not be able to sync properly

I had the same problem, and this is how it worked for me:
On the source root directory -> right click -> Add Framework Support.
A window will open with different categories, such as Java EE, JBoss etc.
Go to 'Spring' category. Then, download the pack of libraries that you need (I used 'Spring MVC').

Project root directory -> right click -> Add Framework Support --> Maven or Gradle --> Click Ok

Right click on the project and select Open In → Terminal
In the terminal, type → mvn -U idea:idea
It will resolve all the classpath issues for the particular project

Add dependency for springframework in pom.xml and run below command from directory where pom.xml exist.
mvn clean install -U
Above command will forcefully download the dependencies.
if you are behind proxy then try below command
mvn clean install -DproxySet=true -DproxyHost=www-proxy.us.com -DproxyPort=80

In my case triggering an Invalidate Caches/Restart helped IntelliJ now find those dependencies.
Following what Mr. BlueSky told in his answer here, I could get the dependencies downloaded.
Actually, the answer by Vinayak Shedgeri should have helped too. For those whom it didn't, you could try the invalidate cache/restart.
P. S.: And going by what could have caused this behavior, you could very well try something as simple as relaunching IntelliJ first. Just a guess.

Please check if you have configured Maven Settings.
IntelliJ (File > Settings > Build,Execution,Deployment > Build Tools > Maven )
Maven home path : C:/Program Files/apache-maven-3.6.0
It resolved my error.

In my case, I was behind Office proxy and that why MAVEN was unable to download the required dependencies on its own !
After switching the network and executing below command : mvn clean install -U, it worked !!

Check if
/Users/<userName>/.m2/
location has settings.xml and toolchains.xml.
I think toolchains might not be necessary but settings.xml is required.
Instructions for creating settings.xml can be found here - https://maven.apache.org/settings.html
My issue was resolved after adding settigs.xml and toolchains.xml to above mentioned location and restarting the IDE.

Maven did not added dependencies on intellij so for this problem I restarted intellij IDE and when this time IDE stared it added dependencies successfully.

import parent folder(Backend) instead of child folder(exam).
child folder(exam)
parent folder(Backend)

I had a few spring-boot modules which were in perfect running state, but suddenly my PC went off and that created issues like: cannot resolve symbol 'springframework' and etc
[Maven -> Reload all maven projects] : this fixed the issue

Related

Intelij - > cannot access java.lang.Object class file for java.lang.Object not found

I'm trying to set up a new project in Intelij. It's a multimodule project, with a maven parent module, and the application server is WebSpere 9.0.5.0. The problem I encounter is when I ty to run it, I get the error java: cannot access java.lang.Object class file for java.lang.Object not found and then java: cannot find symbol symbol: class String for every single String in the code. If I click on a String to see the problem and see the fix of Intelij, it add the import org.apache.xpath.operations.String;
I'd the same problem, but with Android Studio, similar anyway, try this:
In toolbar: File -> Invalidate Caches / Restart... -> Invalidate and restart
I had the same problem, and in my case, invalidate caches didn't work. A colleague of mine pointed out: make sure in the definition of your SDK, the vm.jar file is included (File > Project Structure > Platform Settings > SDKs).
I added this file to the classpath and the red signs disappeared:
$PATH_TO_SDK/jre/bin/default/jclSC180/vm.jar
If this path does not exist for your SDK, find it!
find $PATH_TO_SDK -name vm.jar

Error:scala: 'jvm-1.8' is not a valid choice for '-target' in sbt project

I have a scala,sbt project to run and getting the exception below. Tried to find the solution on internet, only gradle related solutions were available.
Error:scala: 'jvm-1.8' is not a valid choice for '-target'
Error:scala: bad option: '-target:jvm-1.8'
I tried changing the compiler config and other intellij idea settings but unsuccessful to get rid of this issue.
What is missing here ?
Attached the screenshot.
This is the setting you are missing in SBT (added in build.sbt):
javacOptions ++= Seq("-target", "1.8")
encountered same issue with gradle. turns out need to update gradle to latest version. you might would like to try same for SBT.

Testing Java code with Groovy under Intellij: unable to resolve class GroovyTestCase

I need to write a short test for some Java code. I used CTRL+SHIFT+T to generate one with IntelliJ, and selected "Groovy JUnit" as the testing library, then wrote the following test:
package util
class FibonacciHeapTest extends GroovyTestCase {
FibonacciHeap<Integer> heap
void setUp() {
super.setUp()
heap = new FibonacciHeap<>()
}
void testAddInOrder() {
testForItems 1..1000
}
private void testForItems(Range<Integer> items) {
items.each {heap << it}
assertEquals heap.size, items.to
items.each {assertEquals heap.remove(), it}
}
}
However, when I right click on the test case in the project window, I don't get the "Run All Tests" option that I normally do with JUnit tests, and the compiler throws the following error:
Information:2/4/15 8:15 PM - Compilation completed with 2 errors and 0 warnings in 2 sec
/home/patrick/IdeaProjects/hackerrank/src/test/java/util/FibonacciHeapTest.groovy
Error:(3, 1) Groovyc: unable to resolve class util.FibonacciHeap
Error:(9, 1) Groovyc: unable to resolve class GroovyTestCase
Trying to import GroovyTestCase or FibonacciHeap manually causes the same error. IntelliJ does not add any import statements when I let autocomplete finish the names for me, like it usually would with Java code.
What am I doing wrong?
This worked for me :
Open Gradle window (on right side in my case)
Click on refresh button
Done
I had a similar problem with creating test classes in IntelliJ, and it was solved when creating a new directory outside of the com.company folder (where I had the class I wanted to test).
Create a new directory for the test classes on the same level as your src folder
Right click on your new test directory, and "Mark directory as" --> "Test Resources Root"
Now create a test class, which should automatically be added to your test directory.
Build -> Rebuild project in the IDE itself (as opposed to maven, in my case) did it for me.
In my case, what I did to resolve the issue was rather simple.
Close IntelliJ
Open the attached homepage...
Remove your project by clicking on the x then...
Click on Import Project, Navigate to the build.graddle file of your project and open.
That was it and all the Red highlightings disappeared.
maybe you need add groovy-all rather then groovy,such as :
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>${groovy.version}</version>
</dependency>
You have to configure Groovy SDK first. See the screenshot
More detailed description in the official document: Configuring Global, Project and Module SDKs
As #sman591 pointed out in a comment, if you are getting the error:
groovyc: unable to resolve class groovy.util.GroovyTestCase
and you already have groovy as a dependency then you are probably just missing the junit dependency.
In IntelliJ IDEA I re-imported the project. It worked then.
I closed idea. I removed .idea folder in the project. And I imported the project.
Then I needed to set up Groovy, see previous answers, mark test directory as test source in all modules of my project.
I was selecting the root folder which had build.gradle file in it, but it didn't work.
Steps followed are similar to #Pila
close the project from intellij
remove .idea, log, out folders
go to intellij dashboard
import project from existing resources
select build.gradle file <-- this is important
now you should see all the tasks are getting build in the background, and once build is finished all red lines are gone.

Eclipse Error: 'AndroidDataBase' is missing required Java project: 'GoogleMaps'

I am developing an app named "AndroidDataBase".
while am trying to compile in eclipse I am getting this error
Error executing aapt: Return code -1073741819 AndroidDataBase line 1 Android ADT Problem
and
Project 'AndroidDataBase' is missing required Java project: 'GoogleMaps' .
Where GoogleMaps is another androidApp.
I have the GoogleMap.java in AndroidDataBase "Src" folder.
I have tried clean build ,restarting eclipse sort of things ,still no result
Why am i getting this error ,and how to resolve it?
Thanks in advance
I have added the GoogleMap.java
the issue is activity_googlemap its not getting identified
although it is present in res/layout
You need to add the "google-play-services_lib" project as a library project. You will find it in your_sdk_root_path/extras/google/google_play_services/libproject/google-play-services_lib
Set your Project Build Target to Google API Build. From right click on project and go to Preference>Android tab>Select Target build of Google API.
I Dint installed the "Google Play Service" present in the SDK Manager .
Once I did that ,all I need is to follow the solution of # Joan P.S(Stated above I have accepted the ans,thanks to him.).
After that I have to add the Google MAP project(import it to the current work space(another app )) in Properties->Java Build Path->Projects .
That's how it got solved

Eclipse error ... cannot be resolved to a type

I have a dynamic web project that I am working on to migrate a jsp/servlet app from JRun to Tomcat.
I am getting the error: com.ibm.ivj.eab.dab.DatastoreJDBC cannot be resolved to a type.
I have the *.class files sitting inside a com/ibm/ivj/eab/dab folder (exactly how I found them). I have tried creating a jar file and adding that to the build path via "Add External Jar", I have also tried adding an "External Class Folder" and pointing to the folder that contains the "com" directory in question.
Still, the error persists. What is strange is if I start typing the package name eclipse actually auto-completes the class for me! (pictured below). Any ideas would be greatly appreciated. Maybe the classes were compiled for a much older java version and that is causing trouble? Maybe there is something I need to do to ensure the classes end up in the WEB-INF/lib directory?
I
Also If you are using mavenised project then try to update your project by clicking Alt+F5.
Or right click on the application and go to maven /update project.
It builds all your components and resolves if any import error is there.
Right click your project name.
Click Properties.
Click Java Build Path.
Click on Add Class Folder.
Then choose your class.
Alternatively, Add Jars should work although you claim that you attempted that.
Also, "have you tried turning it off and back on again"? (Restart Eclipse).
To solve the error "...cannot be resolved to a type.." do the followings:
Right click on the class and select "Build Path-->Exclude"
Again right click on the class and select "Build Path-->Include"
It works for me.
There are two ways to solve the issue "cannot be resolved to a type
":
For non maven project, add jars manually in a folder and add it in java build path. This would solve the compilation errors.
For maven project, right click on the project and go to maven -> update project. Select all the projects where you are getting compilation errors and also check "Force update of snapshots/releases". This will update the project and fix the compilation errors.
Project -> Clean
can at least sometimes be sufficient to resolve the matter.
For maven users:
Right click on the project
Maven
Update Project
Easy Solution:
Go to
Project property -> java builder path -> maven -> find c3p0-0.9.5.2.jar
and see the location where the file is stored in the local repository and go to this location and delete the repository manually.
Right click Project > Properties
Java Build Path > Add Class Folder
Select the bin folder
Click ok
Switch Order and Export tab
Select the newly added bin path move UP
Click Apply button
Solved the problem by dropping the jar into WEB_INF/lib.
copying the jar files will resolve. If by any chance you are copying the code from any tutorials, make sure the class names are spelled in correct case...for example i copied a code from one of the tutorials which had solr in S cap. Eclipse was continiously throwing the error and i also did a bit of googling ...everything was ok and it took 30 mins for me to realise the cap small issue. Am sure this will help someone
For many new users don't forget to add an asterisk (*) after your import statements if you wanna use all the classes in a package....for example
import java.io.*;
public class Learning
{
public static void main(String[] args)
{
BufferedInputStream sd = new BufferedInputStream(System.in);
// no error
}
}
================================================================
import java.io;
public class Learning
{
public static void main(String[] args)
{
BufferedInputStream sd = new BufferedInputStream(System.in);
// BufferedInputStream cannot be resolved to a type error
}
}
Solution :
1.Project -> Build Path -> Configure Build Path
2.Select Java Build path on the left menu, and select "Source"
3.Under Project select Include(All) and click OK
Cause :
The issue might because u might have deleted the CLASS files or dependencies on the project
Project -> Build Path -> Configure Build Path
Select Java Build path on the left menu, and select "Source"
click on Excluded and then Include(All) and then click OK
Cause : The issue might because u might have deleted the CLASS files
or dependencies on the project
For maven users:
Right click on the project
Maven
Update Project
First you need to update the pom.xml by adding below
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
1] Right click your project name.
2] Click Properties.
3] Click Java Build Path.
4] Check on 'Maven Dependencies' in Order and Export tabl.
In my case, previously it was not enabled. So when I enabled it my #GetMapping annotation works fine..
Also, there is the solution for IvyDE users. Right click on project -> Ivy -> resolve
It's necessary to set ivy.mirror property in build.properties
I just closed all the files and reopened them, and voila!!! Hope this helps someone in the future ;)
Download servlet-api.jar file and paste it in WEB-INF folder it will work

Categories

Resources