IntelliJ IDEA 12 not resolving classes in same package, works in Eclipse
Asked Answered
S

2

5

I'm using IntelliJ IDEA 12 Ultimate for the trial period and came across a bit of a weird issue. While going through the code for a recent tutoring job, I had the screenshot below after trying to compile a class:

enter image description here

The error output is after pressing Ctrl-Shift-F9 to compile the class DrawCircleLab8. As you can see, DrawingPanel is indeed in package lab8 and there are no errors until the compile time exception.

When I imported the exact same project structure in Eclipse, I was able to compile and run without a problem.

Changing the SDK from 1.7 to 1.6 had no effect. How can I resolve this issue for IntelliJ?

Sotelo answered 13/11, 2013 at 20:18 Comment(3)
can you compile through the command line?Majordomo
@AmitApollo, yes, javac works, as well as eclipse. The joker of this deck is idea 12.Sotelo
I've had a similar problem with Android Studio (based on intelliJ). I had to end up using eclipse, and the sad part is it was a simple ubiquitous mail class I was using, and it was a Runtime error not Compile time, which I thought was odd. I know with android studio you have to do a gradlew clean, and then set your compilation dependencies and libraries appropriately. It's definitely an IDE centric issue though!Majordomo
T
7
  1. Try removing import statement for this class and then adding it once again.

  2. From your screenshot I assume that src is already marked as a source root, but to be sure you can do this once again:

    • right-click src in the Project Tree
    • select Mark as... -> Source root
  3. If the above won't work, try to compile whole project first. Compiling only one class may not work if you had never compiled the rest of the project before.

Tuesday answered 13/11, 2013 at 20:23 Comment(3)
The thing about this particular lab is there are three partially implemented lab classes with one utility class. That utility class is used by two of the three lab classes, thus compiling the entire project will throw errors. This is why I wanted to compile each lab class by itself.Sotelo
You cannot compile just some classes. You need to compile all classes that your code depends on, if they're not compiled yet.Weaverbird
Apparently this difference with IDEA is a pain. Eclipse and Netbeans allow me to select a single class to run, and that results in all necessary dependencies being compiled as well. This lack of functionality in IDEA is a serious break from standard functionality conventionSotelo
P
0

These steps might help:

  1. Go to your project directory.
  2. Check for .idea/ directory.
  3. Delete this directory and repeat File -> Open for your project for a fresh import.
  4. Possible that it will ask for import as maven at bottom in case of maven projects.
  5. Errors should be gone once Intellij Idea is done indexing of the project files.

Hope this helps.

Pauli answered 3/9 at 10:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.