Error: Could not find or load main class org.test.spark.streamExample
Asked Answered
M

10

14

I was trying to execute sample basic sparkstreaming example in Scala IDE, but I am getting below error:

Error: Could not find or load main class org.test.spark.streamExample.

Could anyone help me to sort out this please.

Margarita answered 22/12, 2015 at 6:27 Comment(1)
Possible duplicate of Scala project won't compile in Eclipse; "Could not find the main class."Rika
O
6

RightClick on your project and go to properties where you will find Scala Compiler, change target to jvm 1.7 based on your installation and also change Scala Installation dropdown based on version you have installed

Osteopath answered 28/12, 2015 at 9:12 Comment(1)
Nice solution. Worked for me :)Highjack
T
4

This Error May occur for two reasons:

1. When you did not write the main method in the scala program

def main(args: Array[String]): Unit = {
    println("TEst")
  }


2. When you add unsupported jar to the build path of the scala project

Please check the above two scenarios.

Trailer answered 9/12, 2016 at 13:48 Comment(1)
Second reason could be the reason for most of the cases for beginnersAttenweiler
H
2

If your scala file imported from external, check the very top of the code in Main file, just confirm that the package name matches yours.

Holily answered 7/9, 2018 at 4:42 Comment(0)
A
1

The problem occurs mostly due to the incompatible version. Try to build spark with the version of Scala you are using.

Another solution to this problem is :

right click on the Project => Properties => Scala Compiler => Scala Installation => From the drop down select correct version of Scala.(Preferred a lower version of Scala. If not then install a lower version of Scala, then repeat the steps. )

Allan answered 12/4, 2018 at 5:23 Comment(0)
B
1

Error: Could not find or load main class this same problem i have faced for more than 1 days, i have reinstalled IDE(IntelliJ) and i have changed JDK 11 to JDK 8 but nothing was working but finally i resolved it by adding these below two dependency

Solution:

we have to add both dependency spark-core and spark-sql in build.sbt Paackage

1).

libraryDependencies += "org.apache.spark" %% "spark-core" % "2.4.0"

2).

libraryDependencies += "org.apache.spark" %% "spark-sql" % "2.4.0"

i have copied these both dependency from these links

https://mvnrepository.com/artifact/org.apache.spark/spark-core_2.12/2.4.0

https://mvnrepository.com/artifact/org.apache.spark/spark-sql_2.12/2.4.0

Bridge answered 16/11, 2018 at 8:52 Comment(0)
P
0

The main reason for such error is that some compilation errors may exists, it could be some any build path related issue or some code issue. Check the issue in problem tab .

Other than this , check Scala Library version in your POM and Scala Installation version in Scala compiler

Patter answered 6/6, 2017 at 17:24 Comment(0)
O
0

If you are using IntelliJ IDE, then go to the drop down at right top of the IDE window and select "Edit Configuration".

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

enter image description here

Outstanding answered 29/8, 2018 at 17:1 Comment(0)
G
0

In my scenario :

Step 1 : Application is built from sbt

Step 2 : imported the application in eclipse.

Step 3 : When running the application got the following error

1

Solution

In the problems tab if we see the following error

2

sbt was using scala 2.11 and in eclipse we have scala set to 2.12. So if we set the eclipse scala compiler version to 2.11 it will work as shown below

3

Please check this possibility.

Goodin answered 23/1, 2019 at 3:17 Comment(0)
F
0
  • Select the "Scala Library Container[x.x.x]"
  • Right click and open properties
  • Change it to different (lower) version {I tried for 2.11.11}
  • Click apply and close.
Fastback answered 10/2, 2019 at 12:2 Comment(0)
C
0

If you are from LINUX and using only a text editor and a terminal to use scalac and scala, make sure that you have set $SCALA_HOME and $PATH

export SCALA_HOME=/usr/local/share/scala
export PATH=$PATH:$SCALA_HOME/bin

Cartwell answered 26/6, 2021 at 6:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.