40

I have searched for this error, but the answers were for Java, but my case is Scala. I am trying to run this project in IntelliJ IDE sentimenAnalysis, but it throws an error. This is also the structure of the project. Class Not found

Update 1 According to answers, Adding $ at the end of the name of search class enter image description here

Update 2 after adding sbt task: enter image description here

Update 3 My problem was resolved by importing the project, instead of getting it directly from GitHub, probably the manual configuration that Mike Allen said could resolve the problem, but I couldn't successfully apply that.

cela
  • 2,352
  • 3
  • 21
  • 43
sariii
  • 2,020
  • 6
  • 29
  • 57

10 Answers10

44

My problem was resolved when I marked "src" folder as sources root.
Right-click on (folder) src -> Mark Directory as -> Sources Root

enter image description here
enter image description here

blackraven
  • 5,284
  • 7
  • 19
  • 45
Laura Corssac
  • 1,217
  • 1
  • 13
  • 23
  • 3
    This worked for me to remove the error but then it started showing different error of is already defined as . Then I followed https://stackoverflow.com/a/27352057/3209170 and removed src from sources root and it worked. Idk why but if someone is beginner and stuck, try this. – HBB20 Oct 10 '18 at 12:54
  • Worked for me. 1st remove scala folder as source root, 2nd make src folder as source root, run build – Remis Haroon - رامز Jun 19 '20 at 10:28
21

Probably you imported project somehow wrong. I see scala folder is not highlighted as sources. Usually, you don't even need to setup Run configuration manually for Scala SBT project. Do you have Scala and SBT Plugins in your IDE?

You should open SBT projects through "Import project" and choose "build.sbt" file. I would also recommend enabling auto-import to install all of the dependicies.

That's how it look for me: Here how it looks for me

If you still wanna make it manually your configuration should work. That's my Run configuration that works:

My run configuration

SeriousDron
  • 1,296
  • 9
  • 12
  • thanks for your answer, Actually I open the project throgh github, is it okay to do so? – sariii May 24 '17 at 17:17
  • 1
    So your project is misconfigured. You probably can fix it manually. But much easier is just import it as I said from path you have cloned it – SeriousDron May 24 '17 at 17:22
  • but I dont have "import project" in the menu file – sariii May 24 '17 at 17:25
  • Close your current project. You'll have it on IntelliJ IDEA splash window – SeriousDron May 24 '17 at 17:30
  • 1
    It ssems strange when I am importing it works fine, when I just use the github it cant bring the configuration and raises errors, anyway many thanks for your time help and effort – sariii May 24 '17 at 20:54
  • one more question, if you runned the search without any error? cause I am getting null exception error, may I ask you to share your information if you know? thanks :) – sariii May 24 '17 at 21:02
  • Sorry, I don't know. You can create a separate question with full error description, logs, etc, then I hope somebody will help you. – SeriousDron May 25 '17 at 21:16
  • when you directly import scala-project from github, intellij doesn't import it correctly.. you can do git pull and then open project in intellij, that way it always works.. – Shailesh Dec 14 '17 at 08:33
  • simply building the intellij project worked for me. – Tukaram Bhosale Jun 02 '19 at 14:05
7

You will get this error if you tried to open the project and imported it incorrectly. I would open the project like this in Intellij:

File>New> Project from Existing Source>(select) Import project from external model>
(select)sbt

click Next>Finish
alltej
  • 6,787
  • 10
  • 46
  • 87
6

To fix this issue in my project I invalidated caches and restarted:

enter image description here

Adrian
  • 163
  • 1
  • 6
3

In my case the object in the object MyObject extends App was nested, if you have it unested meaning in your scala file it's not under any other object it made it work.

Netsted caused this error in intellij:

object External {
  object MyMain extends App // Could not find or load main class in scala in intellij IDE

}

While the below unested worked:

object External { }
object MyMain extends App // Worked!
Tomer Ben David
  • 8,286
  • 1
  • 43
  • 24
2

Hi I solved this problem by defining the class in src package under main and by setting up the configuration as default.enter image description here

Tutu Kumari
  • 485
  • 4
  • 10
1

Create a new project and make sure SBT is proper loaded along with Scala Library. This happens with many times, bad internet connection or failure of Scala library/SBT loading might be some of the reasons. Best of Luck for Next Project, Happy Developers & Coders.

Ravinder Payal
  • 2,884
  • 31
  • 40
0

Had a similar problem with latest Intellij IDEA build (2022.1.1) and scala 3.1.2 - both sbt and Intellij scala projects. For me the solution was to use non-ascii path.

kwojcikowski
  • 153
  • 1
  • 9
0

@SeriousDron answer helped me with my problem. You need to make sure you have Scala language installed in IntelliJ. You can do this by going to Settings > Plugins > search for "Scala". Now, it will automatically pick up your .sbt file and project.

devo
  • 1
  • 1
-1

I met the same issue, please check the whole execute command and check the configuration, make sure the compiled files path is correctly configured. refer to my screenshot:
refer to my screenshot

Dharman
  • 30,962
  • 25
  • 85
  • 135
NutHu
  • 1