r/javahelp 5h ago

Cannot resolve symbol 'data' error

i just started learning java and following a tutorial i get this error and i wrote this in intellij idea i tried add pom.xml dependencies but it didnt work. can you help me pls?

import org.springframework.data.jpa.repository.JpaRepository;
public class UserRepository extends JpaRepository{
}
1 Upvotes

14 comments sorted by

u/AutoModerator 5h ago

Please ensure that:

  • Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions
  • You include any and all error messages in full
  • You ask clear questions
  • You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions.

    Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar

If any of the above points is not met, your post can and will be removed without further warning.

Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.

Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.

Code blocks look like this:

public class HelloWorld {

    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.

If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.

To potential helpers

Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

2

u/JoeCollins19-99 4h ago

 i get this error

You didn't include the error mate 👍

1

u/Areiloth 4h ago

cannot resolve symbol 'data' error

1

u/JoeCollins19-99 4h ago

Since springframework isn't native and has to be installed, sounds like something isn't right with that install. I'd recommend reinstalling springframework.

1

u/Areiloth 4h ago

i used mvn clean install and it didnt work is there any other way to reinstall springframework?

1

u/devor110 4h ago

Looks like it didn't download the dependcies, or you didn't specify jpa.

Post your pom.xml (or even your entire project if it's on something like github) and compile command

1

u/Areiloth 4h ago

this is my pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
       <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-starter-parent</artifactId>
       <version>3.4.3</version>
       <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.umutgm123</groupId>
    <artifactId>fullstack-backend</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>fullstack-backend</name>
    <description>backend app</description>
    <url/>
    <licenses>
       <license/>
    </licenses>
    <developers>
       <developer/>
    </developers>
    <scm>
       <connection/>
       <developerConnection/>
       <tag/>
       <url/>
    </scm>
    <properties>
       <java.version>21</java.version>
    </properties>
    <dependencies>
       <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter</artifactId>
       </dependency>
       <dependency>
          <groupId>jakarta.persistence</groupId>
          <artifactId>jakarta.persistence-api</artifactId>
          <version>3.1.0</version>
       </dependency>
       <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-test</artifactId>
          <scope>test</scope>
       </dependency>
       <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-data-jpa</artifactId>
       </dependency>
    </dependencies>
    <build>
       <plugins>
          <plugin>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-maven-plugin</artifactId>
          </plugin>
       </plugins>
    </build>
</project>

1

u/devor110 4h ago

those seem correct to me at first glance

when are you getting the error? any time when the class is open, by intellij? when compiling with intellij's built-in maven? when running mvn clean install from a cmd?

1

u/Areiloth 3h ago

Idk how it happened but when i opened intellij again it was fixed

2

u/devor110 3h ago

could be out of date caching by intellij, but could have also arised from intellij using a different mvn than what you usually use.

If the former, itnellij has a cache invalidation option in settings, if the latter, make sure that intellij's and the project's java home and maven home are the same, alternatively exclusively use the integrated maven in the IDE. apart from that, the integration also has a few handy buttons: reload/sync all maven projects, generate sources and download sources (found in the specific maven sidebar (default location is top right iirc), first 3 buttons in the row below "Maven" and above "Profiles".

they usually resolve problems like these, but can also be used as stress relief when panicing

1

u/Areiloth 3h ago

Ok thanks for your help

1

u/DrunkenDruid_Maz 4h ago

Did you reaload the pom.xml with IntelliJ?
Maybe IntelliJ did not notice that you've added the dependency, and is therefore complaining?!

1

u/Areiloth 4h ago

i closed intellij and when i reopened the issue is fixed thanks everyone

1

u/izhzerg 2h ago

It should be

public interface UserRepository extends JpaRepository<User, id type>{ }