"package does not exist" error, despite autocomplete being aware of them

已回答

I'm using classes from a project I have as a dependency, the editor seems to be completely aware of this - it even offered me the appropriate classes when I manually deleted the import statements, and I can see the library in the Project tree under External Libraries, nevertheless, I get a "java: package ... does not exist" upon compilation.

I have tried the Maven>Reimport option, downloading and generating sources, no dice.

Any ideas? Thanks!

9

Does java package correspond to the file location (directories tree)?

Please share a sample project to reproduce the problem.

0

Turns out it was because of a case mismatch between the `pom.xml` and the actual package name (which started with a capital letter) - thanks for the response, though!

0

So, this actually isn't solved just yet - the problem re-appeared, and the case mismatch actually wasn't the issue.

>Does java package correspond to the file location (directories tree)?

I'm not sure what would that mean - there is a .jar that's getting included into the project, as managed by maven.

 

NetBeans compiles the same project fine.

1

Please share a sample project to reproduce the problem.

0

Hi Tomáš Mládek,

What could be the solution?

I have the same problem. The package does not exist during recompile, but the code editor does not say (because the package exists and is in the same directory level).

Thanks.

 

1

Is that a Maven or Gradle project? What's the scope of the dependency in the build system? How did you define it in the build script? What's the exact error? Do you see the jar with the classes reported as missing in the module dependencies? https://www.jetbrains.com/help/idea/creating-and-managing-modules.html#working-with-module-dependencies

0

Hi Serge,

Thanks for the immediate reply.

It is a personal project and a start to work in IntelliJ (no error in Eclipse and works fine in it).

I hope to build and run in IntelliJ only.

Attached is a sub-image of the project. It complains that test.java.pageobjects does not exist, but it is there on the same directory level.

What could be a mistake in the settings?

Thanks.

2

Please show the File Explorer screenshot with the full path of the AmazonPage.java file. Make sure it's not added as a library (to classpath).

0

I'll use cygwin so you can see the directory structure of both pageobjects and tests.

0

Please zip and upload the project at https://uploads.services.jetbrains.com/ and specify the file name here so that we can inspect the settings.

0

The file name is Selenium.zip. 

0

I can't reproduce the issue with the provided project. The package is resolved just fine. Please try File | Invalidate Caches | Invalidate and Restart.

0

After invalidating caches and restarting, same error for me. 

 

 

Can you please show me your results like this?

I'll try to spot the differences.

0

By the way, how about the encoding? What should be the correct encoding in IntelliJ?

Thanks.

0

Please upload the jars used in your project so that I can build it.

0

Ok. It is UTF-8 for AmazonPage.java.

I have zipped and upload the /cygdrive/C/Selenium directory. Selenium.zip is the name.

0

Opps ... still at 70% ...

0
Selenium.zip (101.1 mb) 100%

 

[Select files] [Upload files]

 

Uploading...
File uploaded: Selenium.zip
Upload complete!
0

The file is not present because it has the same name as your previous upload. The file name must be unique. Please try again.

0

C--Selenium.zip is now uploaded.

0

It looks like you are not using the Java module system properly. I'm getting a lot of different errors related to the modules not available. If I remove the module-info.java file and change the language level to 8, it builds without errors in IntelliJ IDEA 2019.3.3:

1

Yes! That's it! I just removed module-info.java!

I actually did not create that file. Does IntelliJ create that file?

Thanks for your help, Serge!

Thanks for replying even if the original question was more than 3 years ago. I could not find any solution on the Internet.

I am now able to run AmazonTest.java.

 

  

 

0

IntelliJ IDEA doesn't create this file, it was already present in your project.

0

Ok. I must have created it inadvertently in File -> New -> module-info.java.

 

Thanks for your help again!

0

I have the same issue here. After tons of research and trials, I couldn't resolve the issue. Note that I've asked in StackOverflow but none of the answers seems to work.

IntelliJ can resolve the packages. But it can't compile them:

All needed libraries are in the pom.xml. Note the maven can run the project but IntelliJ cannot.


This is the error that drives me crazy for months:

PS: I've tried all the above solutions and others on the internet but none of them work. Help would be much appreciated!!

2

Hamza Belmellouki

There is a known bug with Maven builds in 2020.1 and 2020.1.1 versions: https://youtrack.jetbrains.com/issue/IDEA-237320 .

Does the project build in 2019.3.4 release available at https://www.jetbrains.com/idea/download/previous.html ?

See if https://youtrack.jetbrains.com/issue/IDEA-239150#focus=streamItem-27-4117814.0-0 helps.

If the issue occurs with 2019.3.4 version, please share a sample project to reproduce zipped: https://uploads.services.jetbrains.com/ and the logs (https://intellij-support.jetbrains.com/hc/articles/207241085).

1

I had the same problem

IntelliJ doen't find the packages however if I run the gradle build it works

I can even star the project... but I was unable to run unit tests because it says that it could not find Test Class

So, I'd tested many solutions Rebuild, File> Invalidate Cache... and nothing seems to be working..

the way I found is to remove .IML file I had... and reopen the project.. it works.

4

请先登录再写评论。