score:22

Accepted answer

I think this should be your folder structure

Scala0
└── src
    └── main
        └── scala
            └── com.ks.sparkscala
                └── FriendsByAge

In your case create a folder main/scala inside src and copy the package inside it.

Please follow here for the project structure

I hope this helped!

score:0

I had a similar problem. I’ve got Could not find or load main class in IJIdea IU-182.4892.20 / Scala 2.13 for .scala file with such structure:

package ...

import ...

object Main extends App {
...
}

//other traits, classes, objects

But when I moved //other traits, classes, objects to the separate .scala file in the same package my problem was solved.

score:0

I was experiencing the same error message and the below solution worked for me:

  1. Right-click on the project.
  2. Click on Scala.
  3. Choose the option "Set the scala installation".
  4. Select the Scala Installation (I selected "Fixed Scala Installation: 2.10.6(bundled").

After this, it ran fine and did not give that error message.

score:0

Another one solution. I had a similar problem on project with Scala + SBT.

How I solved this one:

  1. Run my project via SBT like this: sbt my-project/run
  2. Stopped it (Ctrl+C)
  3. Run debug -- it works again.

score:0

There were numerous things I need to solve this problem, and I think every one of them was important.

  1. Make sure the scala file in question is in the "src" folder.
  2. Make sure it is an object (if your inner class/object is an object).
  3. Make sure the filename and the class/object name is the same.

(The following instructions work in IntelliJ)

If #1 is not true, here's the easiest way to fix it:

  1. Click and drag your file into the "src" folder in IntelliJ. Say "yes" to any refactorings.

If #2 or #3 is not true, here's the easiest way to fix it:

  1. Copy your code (CTRL+A, CTRL+C)
  2. Right-click your "src" folder and select "New Scala class"
  3. Type in the name of your class / object
  4. Select "Object" if your file will contain a top-level object instead of a top-level class
  5. Press ENTER (or select the appropriate confirmation button)
  6. Paste in your code (CTRL+A, CTRL+V);

RESULT: Now you should have a file called "YourClass.scala" in your "src" folder, and it should have an orange icon if it's an object. The filename should match the name of the toplevel class/object. And you should be able to right-click it and run it. And then after you do that, you should be able to just press the play button in the top right corner. And it should work.

score:1

For Intellij IDE, use the following procedure:

  1. Go to the drop down at right top of window and select "Edit Configuration".

  2. On the pop-up screen, select "Scala-console" in left side, and in the right side, select your module name under "Use class path and SDK of module.

enter image description here

score:1

As far I can see your package structure is com.ks.sparkscala which is different from the declared one in FriendsByAge.scala, com.sundogsoftware.spark Hope this helps.

score:1

For the reference of the IntelijIDEA I guess somehow you would be using the scala plugin, in that case, there is a fix to the above-mentioned question:

Error: Could not find or load main class in both Scala IDE https://youtrack.jetbrains.com/issue/SCL-13636

Try to reimport the project and overwrite the .idea directory as while importing as a Existing Project it will prompt to overwrite the .idea configuration. Hope that Fix

FYI Its a UNRESOLVED issue

score:4

In the eclipse -->project properties-->scala compiler ---> change the scala installation.

It is working for me .


Related Query

More Query from same tag