Java Package Does Not Exist Error

Viewed 349909

So there's a folder /usr/share/stuff in the root directory

in stuff there are a bunch of java files with package org.name definitions at the top

I am running javac test.java where test.java is in a subdomain

I added /usr/share/stuff to my class path.

and at the top of test.java I add import org.name

But I get a package does not exist error...why?

10 Answers

Just reimport didn't work. Following worked for me.

File -> Invalidate Caches /Restart

Then

Build -> Rebuild Project

That will reimport maven project.

Right click your maven project in bottom of the drop down list Maven >> reimport

it works for me for the missing dependancyies

If you are facing this issue while using Kotlin and have

kotlin.incremental=true
kapt.incremental.apt=true

in the gradle.properties, then you need to remove this temporarily to fix the build.

After the successful build, you can again add these properties to speed up the build time while using Kotlin.

You should add the following lines in your gradle build file (build.gradle)

dependencies { 
     compile files('/usr/share/stuff')
     ..
}

If you have 2020 version, that you've most likely got a bug, like the one I got. Tried multiple things, but what helped me is a very simple thing. Settings -> Build, Execution, Deployment -> Build Tools -> Maven. Put a checkmark for Override of Local Repository, but leave the default value. Apply, OK. You can get an error, that's ok. Just press "Reload all Maven Projects" button (two rounded arrows, looks like regular Refresh button) in Maven tab on the right of the screen. Maybe clean and install. Should work after that.

I came to this question because a bringing a file from one folder to another caused this error for me. The command that fixed it is below. I had the same package in multiple directories, and it was only looking at one of the directories.

So, if it's a Maven project, try mvn clean install --update-snapshots

Related