If you’ve encountered the Cannot resolve symbol... error in IntelliJ IDEA after switching branches, you’re not alone. This frustrating issue can occur even when your code is error-free and compiles successfully from the command line.

Solution

To resolve this issue, follow these steps:

  1. Remove the targets folder, if it’s a maven project, you could do mvn clean
  2. Expand the Maven plugin in IntelliJ IDEA’s sidebar.
  3. Click the Reload All Maven Projects button with the refresh icon.

By following these steps, you can make the Cannot resolve symbol... error vanish and continue coding smoothly. This simple fix can save you time and frustration.

Reference

For more details and community discussions on this issue, check out this Stack Overflow thread.