Scala IDE Error -could not find/load main class - java

I am using Scala IDE 4.4.1.,using the jdk 8.When I try to run a scala program ,getting the error "Error: Could not find or load main class example.Credit" .

I was stuck with the same error a few days ago. In my case, it was an incompatibility of my JDK and the selected target JVM for my Scala project.
To check your current Java version, run java -version on the command line. To check your project JVM target in Eclipse, go to "Project > Properties > Scala Compiler" and check the target JVM (choose the same version as your current Java).
Hope it helps.

You should write object instead of class

I was having the same problem so that is how I came to this link & would like to share my findings. In my case I found that incompatible jars where present due to it was throwing error. After providing correct jar issue was resolved.

I used Scala for Eclipse IDE,
The solution for this could be right click on project and select scala -> Set the Scala Installation, will set the scala path to this project and rebuild the same.
Hope this helps you.

If the above mentioned solutions are already configured in your system and still getting this error then consider reading my answer. When incompatible scala jars are referenced by projects, a red cross mark is shown at project level and no errors are shown in scala files. In this situation scala code doesnt compile and when executed shows the message "error could not find or load main class scala". Best solution is to go to the scala installation folder and to check if the jar is present there, if present then reference it else reference jar files that do not show error (red mark) at project level or at source code.

Related

error java.lang.ClassNotFoundException when try to use OneWayAnova Class

I'm using eclipse RCP (helios), and I need to add statistics functions.
In the editor, I have no problem, no error.
But when I run or debug the project, I get:
java.lang.ClassNotFoundException:
org.apache.commons.math3.stat.descriptive.SummaryStatistics error.
first question, the library says si java 1.5+ compatible, I'm running on 1.6.
is this ok?
besides build path... is there any other way to set classpath ?
Best Regards

IntelliJ IDEA is not recognizing my java files as runnable and instead wants to run the class files. Any ideas of how to fix?

Anytime I try to run a java file by clicking run, it instead tries to run the class file and thus gives a no main method error.
When I try to right click on a java file and run that, it doesn't recogize it as a file that is runable.
I am still able to run programs from the command prompt but I would prefer to be able to run them in IntelliJ.
This occurred after trying to create a Class path when using JSon Libraries.
Edit:
Normally it shows java files with this icon:
But instead it's showing this icon for java files:
I think the change in icon might have something to do with it.
Edit 2:
the exact error I get is "C:\Program Files (x86)\Java\jdk1.8.0_181\bin\java.exe"...bunch of other program file locations
Error: Could not find or load main class sample.Main
Process finished with exit code 1
I had the same problem and found out that my src wasn't marked as Sources Root. To change this:
right-mouse click on your src
navigate to "Mark Directory As"
choose "Sources Root"
It will now recognize your files correctly and your main classes will be able to run again
IntelliJ not recognizing my .java-files
Problem solved
I had a similar problem.It wouldn't pick up ModlServer in any project. (Not just limited to the one I had open).
I had to file -> Manage IDE Settings -> Restore Default Settings
Note: I lost all my live templates, fonts, etc so just a heads up.
I restarted my computer and that somehow fixed it.
My issue was that I have multiple modules for my project and the module I was working on (where java files were not recognized) was not included in the main pom. I just added that module in the main (project) pom and it worked.
Right click on the project and click 'Add framework support' all directories and classes should now be the right type.
I've fixed this at Intelij2023 by using JDK17 as the JDK the IDE uses to import java source files.
Mind this JDK version does not need to be the same you use to build your project.
Go to: Settings > Build, Executio, Deployment> Build Tools > Maven > Importer
Set the JDK For Importer to zulu-17
I'm using zulu-17 as JDK for imports and coretto-8 to build the project (having JDK version 8 seems to be preventing intelij to properly recognize the project structure)
If you are using Maven or Gradle, try to re-import the project and see if that helps. Could be that your IDEA project has some incorrect settings in it set by mistake, so this way those would be removed.

Using codenameone with lombok in Eclipse

I wonder if anyone is using codenameone with lombok in Eclipse. I've googled, but all I could find is an old question of mine.
A tiny success
I've tried it, took a demo project, modified nothing and opened it in my Eclipse configured for Lombok. When compiling, I got the same stacktrace as here. I've added
/usr/lib/jvm/java-8-oracle/lib/tools.jar
to the path under Preferences -> Installed JREs -> Edit -> JRE system libraries (which may be a pure non-sense) and it didn't help.
Then I've replaced compiler="modern" by compiler="extJavac" in build.xml and it compiles. I can even use Lombok annotations and they compile and work in the simulator.
The problem
I'm afraid, this was the simple part. I guess, for submitting, I need to replace the source code by the output of delombok. I've tried to submit it as is and nothing happened (no error, no response).
Has anyone done it already?
Any tips?
You shouldn't change the classpath but if the bytecode has access to the properties then it should "just work". If you look at the build.xml file you will notice that it has targets for every one of the supported platforms and before the target occurs you will see a compilation target that packages the JAR that's sent to the servers.
Steve wrote a post about porting other languages to Codename One. This is simple by comparison.
It actually works! All I had to do was to
add the path to lombok.jar to the Java Build Path1
in the javac call of the jar task
replace compiler="modern" by compiler="extJavac"
add the path to lombok.jar to the classpath
1 This is not recommended as the dependency is unavailable on the build server, but that's exactly right. Lombok is a compile-time only dependency and the build seems to be based on the dist.jar, where Lombok has already done its job.
One year later: There was a problem with my old setup, so I installed everything anew and it seems to work. Just note that there are three javac tasks in the build.xml.

Issue about Intellij IDEA with scala

I have a scala project but I don't know how to run it :
This is an java project and it has a button in main Method line:
my project is this :
what should I do to find the button to run my scala program
there is no run button
As I cannot comment, I will write here: you must point the scala class and right click on it, and then you have the Run. In the pictures you are trying to run the java class
Few things:
a) Check to make sure, your source directory is included as module
i.e. File > Project Structure. In the attachment below you see my modules
b) Check to make sure you have included your scala library, I believe you have this setup.
c) Last resort, see if you can add your object as Application
i.e. Run > Edit Configuration & the following
Hope this helps, enjoy!
You need a scala plugin to run a scala file. And find more at the get started documentation of idea.

Intellij not able to run Scala Code

I have a project that uses both Java and Scala code. When I am trying to run a main function from Scala on Intellij 13.1.4 with Scala Plugin 0.38.441 installed I get the following error
Error:scalac: Error: Scala instance doesn't exist or is invalid:
version unknown, library jar: /home/arpit/.m2/repository/org/scala-lang/scala-library/2.11/scala-library-2.11.jar, compiler jar: /home/arpit/.m2/repository/org/scala-lang/scala-compiler/2.11/scala-compiler-2.11.jar
sbt.InvalidScalaInstance: Scala instance doesn't exist or is invalid:
version unknown, library jar: /home/arpit/.m2/repository/org/scala-lang/scala-library/2.11/scala-library-2.11.jar, compiler jar: /home/arpit/.m2/repository/org/scala-lang/scala-compiler/2.11/scala-compiler-2.11.jar
at sbt.ScalaInstance$.slowActualVersion(ScalaInstance.scala:122)
at sbt.ScalaInstance$.sbt$ScalaInstance$$actualVersion(ScalaInstance.scala:119)
at sbt.ScalaInstance$$anonfun$actualVersion$1.apply(ScalaInstance.scala:32)
at sbt.ScalaInstance$$anonfun$actualVersion$1.apply(ScalaInstance.scala:32)
at scala.Option.getOrElse(Option.scala:120)
at sbt.ScalaInstance.actualVersion$lzycompute(ScalaInstance.scala:32)
at sbt.ScalaInstance.actualVersion(ScalaInstance.scala:32)
at org.jetbrains.jps.incremental.scala.local.CompilerFactoryImpl$.org$jetbrains$jps$incremental$scala$local$CompilerFactoryImpl$$getOrCompileInterfaceJar(CompilerFactoryImpl.scala:79)
at org.jetbrains.jps.incremental.scala.local.CompilerFactoryImpl$$anonfun$getScalac$1.apply(CompilerFactoryImpl.scala:43)
at org.jetbrains.jps.incremental.scala.local.CompilerFactoryImpl$$anonfun$getScalac$1.apply(CompilerFactoryImpl.scala:42)
at scala.Option.map(Option.scala:145)
at org.jetbrains.jps.incremental.scala.local.CompilerFactoryImpl.getScalac(CompilerFactoryImpl.scala:42)
at org.jetbrains.jps.incremental.scala.local.CompilerFactoryImpl.createCompiler(CompilerFactoryImpl.scala:21)
at org.jetbrains.jps.incremental.scala.local.CachingFactory$$anonfun$createCompiler$1.apply(CachingFactory.scala:23)
at org.jetbrains.jps.incremental.scala.local.CachingFactory$$anonfun$createCompiler$1.apply(CachingFactory.scala:23)
at org.jetbrains.jps.incremental.scala.local.Cache$$anonfun$getOrUpdate$2.apply(Cache.scala:20)
at scala.Option.getOrElse(Option.scala:120)
at org.jetbrains.jps.incremental.scala.local.Cache.getOrUpdate(Cache.scala:19)
I also checked for compiler settings under Project setting in IntelliJ and for Scala Compiler it says "Nothing to show here in external build mode". Can this be the problem?
It seems that the compiler cannot read the version of the scala-compiler jar. Maybe it is corrupted. Try to redownload it or to use another version. To set another compiler library go to Project Structure/Facets/Scala facet of your module and select a suitable library.
If it does not work please create a ticket on the bugtracker (with the attached compiler library):
http://youtrack.jetbrains.com/issues/SCL
Also you can try to change the type of the incremental compiler in Settings/IDE Settings/Scala
There is nothing wrong with the Compiler/Scala Compiler settings.
I had the same problem, that's what I've done:
(After installing IntelliJ and SBT) I downloaded Scala as well from this website and installed it.
Then I went to File -> Project Structure -> Libraries and I removed the existing library.
Afterwards, I clicked the "+" symbol and "Scala SDK" and found the Scala installation folder (C:\Program Files (x86)\scala\ in my case).
And followed the instructions. Then everything worked fine...
Hope it helps...
I had similar issue when run Idea under the root user. Idea was not able to find the scala library. I solved the issue by quitting the Idea and run it under my current user.
in my case i went into Compiler/Scala Compiler settings and deleted additional compiler options (make -transitive)

Categories

Resources