Reputation: 9668
When I try to make a project in IntelliJ I receive the following error on this line:
Sentence sent = new Sentence();
sent.emptySegments();
Error:
Error:(151, 10) java: cannot access javax.xml.bind.RootElement
class file for javax.xml.bind.RootElement not found
Sentence
is a class which implements the RootElement
interface
import javax.xml.bind.RootElement;
...
public class Sentence extends MarshallableRootElement implements RootElement {
All packages exist and I can jump to declaration of each interface or class but I don't know why IntellJ says it cannot access or find them? However RootElement
is an interface and not a class
public interface RootElement extends Element {
void validate() throws StructureValidationException;
}
The above declaration is in a jar file named jaxb-rt-1.0-ea.jar
and it exists in the Project librarians.
Upvotes: 53
Views: 123046
Reputation: 901
In my case there was an old .iml file in the module causing these problems. So if nothing else worked for you, try looking for one.
Upvotes: 0
Reputation: 111
If you've made it this far because rebuilding or invalidating the cache didn't work work you, I found that deleting the class and adding a new one with the same code worked.
Upvotes: 1
Reputation: 10695
Try this
(See Invalidate caches on IntelliJ's manual)
Upvotes: 133
Reputation: 51
If it is a single file, you can try deleting the file and undoing it. It seems to reindex that particular file alone, which is much faster than Invalidate Caches/Restart. As a precautionary measure, you can take a backup of the file before deleting, just in case if something goes awry.
Another reason might be different versions of same library with more/less methods. This happened for me with Gradle. Sometimes it compiles fine and sometimes, it doesn't. Just find and remove the unnecessary ones.
Upvotes: 2
Reputation: 107
I removed this location "amazonaws" file and clean install later run
/Users/testuser/.m2/repository/com/amazonaws
Upvotes: 0
Reputation: 1368
Similar problem can happen if a library is imported with maven scope runtime.
In such case it isn't accessible by your classes located under src/main/java
.
Only classes in src/test/java
can directly use runtime dependencies.
Upvotes: 0
Reputation: 1
For me just worked, turn off windows defender / add exclusion project folder / idea process.
Upvotes: 0
Reputation: 27904
My Gradle/IntelliJ "big hammer"
(Optional, but preferred). Close all instances of IntelliJ or any other Java IDE.
delete the ".idea" folder (<< intellij specific, or whatever "workspace" folder your IDE uses)
..............
./gradlew --stop
OR
gradle --stop
(now delete the folders)
rm -rf $HOME/.gradle/caches/
rm -rf $HOME/.gradle/build-cache-tmp/
(now resume normal gradlew commands like:)
./gradlew clean build
Upvotes: 0
Reputation: 159
Deleting the .idea
folder and then running Invalidate Caches/Restart
worked for me.
Upvotes: 7
Reputation: 41
It also may be because you don't have dependencies in classpath, which used in dependencies.
For example: you use library A, but class you're using from A has superclass from library B. But you didn't add B to classpath.
Upvotes: 4
Reputation: 231
File -> Invalidate Caches/ Restart this worked for my after long hours of effectiveless
Upvotes: 23
Reputation: 9668
The project contained several modules. While the library was added to the project libraries, some modules lacked it in their dependency part. So I solved the problem using the following steps in IntelliJ
Creating a module library and adding it to the module dependencies:
Upvotes: 25