Kotlin - Error: Could not find or load main class _DefaultPackage - kotlin

I followed the Kotlin tutorial for eclipse here : Getting Started With Eclipse Luna
However, I'm running into this error:
Error: Could not find or load main class _DefaultPackage
Anyone who knows to get around this?

This was a severe bug (KT-10221) in automatic generation of Launch Configuration in plugin version 0.4.0. It was fixed in 0.5.0 so the recommendend way to workaround is to update plugin.
The source of the problem was that the plugin used an old pattern for generating name of the class for main function that had been abandoned by Kotlin compiler.
It's possible to workaround it by editing launch configuration (Eclipse Menu -> Run -> Run Configurations...) by hand and changing Main class field in Java Application group. If the file is named hello.kt with no package directive, as it is described in tutorial, than corrected string should be HelloKt.
If file has name other.kt with package my.tutorial than the Main Class should contain my.tutorial.HelloKt. You can read more about it in the section Package-Level Functions of Calling Kotlin From Java page.

I have been getting the same issue. And after putting the right compiler output path, it got resolved.
Go to Project -> Project Compiler output :
In the text box, fill this:
[Absolute Path]/{Project Name}/out

In my case I was having this problem while trying to run the program using the Application Gradle plugin. The problem was in the mainClassName property using single quotes instead of double ones
This didn't work:
mainClassName = 'demo.HelloWorldKt'
With double quotes, it works:
mainClassName = "demo.HelloWorldKt"

For me it worked after I installed the correct JDK. I first had JDK 11 but the tutorial I did was with JDK 8 so after I installed this and set it in the "installed JREs" options it found the main class without having any "mainClassName" or any other option in the build.gradle file.

For me, it worked in a fresh eclipse workspace. Possibly, the Kotlin eclipse plugin is not playing well with other plugins (in my case, PyDev).

I'm creating a Kotlin Application with JavaFX and I had this issue until I went to:
Run > Run Configurations > Java Application > Common
I unticked "Allocate console" and it fixed the issue.

Related

Problem building project in IntelliJ 2020.1

I'm trying to build my project but I can't.
I get this error:
Error:Cannot run program "C:\tools\jdk8.0.191\bin\java.exe" (in directory "C:\Users\"my user"\AppData\Local\JetBrains\IntelliJIdea2020.1\compile-server"): Malformed argument has embedded quote: -Djava.endorsed.dirs=\"\"
Do anyone know what to do about this? Iøm trying to build in IntelliJ 2020.1
Best Regards
It might be related to more strict command-line processing in JDK on Windows after JDK-8221858 (private) security patch see this comment for details.
Try following workaround: Help -> Edit Custom VM Options action and add the following line at the bottom of the file: -Djdk.lang.Process.allowAmbiguousCommands=true and restart IDE.

IntelliJ Error:java: java.lang.ExceptionInInitializerError

Every time I encounter this exception in IntelliJ, I fix it trivially and forget the fix easily.
Code:
package whatever;
import org.junit.Test;
public class TestClass
{
#Test
void test() {}
}
Scenario:
Add new TestClass.
Right-click TestClass.
Select "Run 'TestClass'" to run test cases.
The "Messages Build" pane shows:
Information:javac 9-ea was used to compile java sources
Information:Module "dummy" was fully rebuilt due to project configuration/dependencies changes
Information:8/16/17 11:35 PM - Compilation completed with 1 error and 0 warnings in 1s 663ms
Error:java: java.lang.ExceptionInInitializerError
What can possibly go wrong?
What are the likely issues in this simple scenario?
IntelliJ: COMMUNITY 2017.1 (idea-IC-171.4424.56)
To fix the issue, I do:
File -> Project Structure... -> Project Settings / Project -> Project SDK.
Change from "9-ea" to "1.8".
DETAILS
Apparently, the issue is discrepancies in selected JDK-s to build (java 9) and run (java 8).
I'm not sure how "9-ea" gets re-selected there for the same project - neither IntelliJ itself runs in "9-ea" JRE (according to Help -> About) nor JAVA_HOME env var is set to it nor other possible settings (like Maven -> Runner) suggest any "9-ea".
I also didn't manage to run the test under the same JDK (java 9) which it gets compiled under. However, it's unclear what JDK tests are run under because IntelliJ reports only about JDK for compilation.
If you use Lombok: For me it was a solution to set the newest version for my maven lombok dependency in the pom.xml.
*<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
<version>1.18.8</version>
</dependency>*
I was facing same error when i tried to run my application in IntelliJ-2019.2 version. Below are the steps i followed to resolve this issue.
Versions:
IntelliJ : IDEA-IntelliJ-2019.2
Java : jdk1.8_221
Go to below path in IntelliJ
File -> Project Structure -> Project -> Project SDK -> (select java version which you want to use )
(In my case under 'project SDK' java-11 was selected, I changed it to 'java8')
Click on 'Apply' and then 'OK'.
I feel I ran into this issue because IntelliJ was trying to compile my java classes using in-built java-11 whereas my java classes are built on java-8. So when i explicitly configured java-8 in IntelliJ, It worked!! Hope this helps.
I started seeing this exception once I installed Java 11 in my machine. JAVA_HOME was by default pointing to Java 11 and my project was still in Java 8. Changing JAVA_HOME to Java 8 jdk fixed the issue for me.
If you have multiple projects each running on a different JDK, use this command to temporarily change the Java version per command.
JAVA_HOME=/path/to/JVM/jdk/Home mvn clean install
If you have recently updated your IDE then you can try these steps.
Delete .idea directory for the idea project/workspace
Then go to File -> Invalidate Caches / Restart...
Once Idea is restarted re-add/import your module(s)
I faced a similar issue with JARs and Jena (while run from IntelliJ it works).
I was using Apache Jena v4.0.0 in my project and have built a JAR (with a main class for the JAR to act as a console app).
The JAR builts successfully with IntelliJ but when run throws java.lang.ExceptionInInitializerError ... Caused by: java.lang.NullPointerException. NPE suggests that something was not initialized properly.
The jar built with previous version Jena 3.17.0 works perfectly.
What I did to fix it
I've opened both the JARs, compared their META-INF folders and encountered the difference in
my.jar\META-INF\services\org.apache.jena.sys.JenaSubsystemLifecycle
The new version (jena v4.0.0) contains only one line:
org.apache.jena.tdb.sys.InitTDB
The old version (jena v3.17.0) contains two different lines:
org.apache.jena.riot.system.InitRIOT
org.apache.jena.sparql.system.InitARQ
I've added the old two lines to the file and repacked new JAR with it:
org.apache.jena.tdb.sys.InitTDB
org.apache.jena.riot.system.InitRIOT
org.apache.jena.sparql.system.InitARQ
It resolved my issue.
Update: recent Jena v4.4.0 builts with the same "bug".
I'm not an expert and there is probably a better way than patching a JAR by hand.
But I still hope that this solution will help someone like me.

Quasiquotes in Intellij 14?

After installing the newly released IJ14 Community Edition - the quasiquotes (which had been working on IJ13) popped up on the radar.
Is there an IJ setting to enable this?
BTW this is a maven build (and works in 13.1 just fine!). Here is the section of the build related to the quasiquotes. I have not seen any mention of the plugin not working properly in 14, but input here would be appreciated.
<!-- The following plugin is required to use quasiquotes in Scala 2.10 and is used
by Spark SQL for code generation. -->
<compilerPlugins>
<compilerPlugin>
<groupId>org.scalamacros</groupId>
<artifactId>paradise_${scala.version}</artifactId>
<version>${scala.macros.version}</version>
</compilerPlugin>
</compilerPlugins>
UPDATE I just installed the 14.0.1 update from 11/11/14. This time I tried Intellij Ultimate : but Quasiquotes are still not working.
UPDATE I have opened a JIRA with JetBrains. https://youtrack.jetbrains.com/issue/IDEA-133993
I think there is a workaround to get it running:
You have to go to the IntelliJ settings, to the "Scala Compiler" and add a plugin: "/home/YOURUSERNAME/.m2/repository/org/scalamacros/paradise_2.10.4/paradise_2.10.4-2.0.1.jar"
The problem involves the paradise plugin that provides support for quasiquotes with scala 2.10. It is not working in IJ14 presently.
UPDATE The following is new info on the building with Spark page
https://cwiki.apache.org/confluence/display/SPARK/Contributing+to+Spark#ContributingtoSpark-IntelliJ
"Rebuild Project" can fail the first time the project is compiled, because generate source files are not automatically generated. Try clicking the "Generate Sources and Update Folders For All Projects" button in the "Maven Projects" tool window to manually generate these sources.
Compilation may fail with an error like "scalac: bad option: -P:/home/jakub/.m2/repository/org/scalamacros/paradise_2.10.4/2.0.1/paradise_2.10.4-2.0.1.jar". If so, go to Preferences > Build, Execution, Deployment > Scala Compiler and clear the "Additional compiler options" field. It will work then although the option will come back when the project reimports. If you try to build any of the projects using quasiquotes (eg., sql) then you will need to make that jar a compiler plugin (just below "Additional compiler options"). Otherwise you will see errors like:
/Users/irashid/github/spark/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/codegen/CodeGenerator.scala
Error:(147, 9) value q is not a member of StringContext
Note: implicit class Evaluate2 is not applicable here because it comes after the application point and it lacks an explicit result type
q"""
^
It's s not q:
val x = 5.0
println(s"$x.toInt")
I loaded spark up in Intellij 13 and the macro paradise backport of quaisquotes still shows an error, I don't see how intellij would be able to support this syntax as it's a compiler plugin:

What's the reason for "Error:Cannot determine Java VM executable in selected JDK"?

I am using IntelliJ IDEA 13.1.4 and also tried the latest release 14.
Running SBT I get the following error:
Error:Cannot determine Java VM executable in selected JDK
I have JDK 1.7 installed on my machine and on PATH.
In the logs (~/Library/Logs/IntelliJIdea14/idea.log on MacOS) there's the following stack trace:
2014-11-03 11:22:05,054 [4896641] WARN - nal.AbstractExternalSystemTask - Cannot determine Java VM executable in selected JDK
com.intellij.openapi.externalSystem.model.ExternalSystemException: Cannot determine Java VM executable in selected JDK
at org.jetbrains.sbt.project.SbtExternalSystemManager$$anonfun$10.apply(SbtExternalSystemManager.scala:97)
at org.jetbrains.sbt.project.SbtExternalSystemManager$$anonfun$10.apply(SbtExternalSystemManager.scala:97)
at scala.Option.getOrElse(Option.scala:120)
at org.jetbrains.sbt.project.SbtExternalSystemManager$.executionSettingsFor(SbtExternalSystemManager.scala:96)
at org.jetbrains.sbt.project.SbtExternalSystemManager$$anonfun$getExecutionSettingsProvider$1.apply(SbtExternalSystemManager.scala:54)
at org.jetbrains.sbt.project.SbtExternalSystemManager$$anonfun$getExecutionSettingsProvider$1.apply(SbtExternalSystemManager.scala:54)
at org.jetbrains.sbt.package$$anon$3.fun(package.scala:29)
at org.jetbrains.sbt.package$$anon$3.fun(package.scala:28)
at com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil.getExecutionSettings(ExternalSystemApiUtil.java:590)
at com.intellij.openapi.externalSystem.service.ExternalSystemFacadeManager.a(ExternalSystemFacadeManager.java:201)
at com.intellij.openapi.externalSystem.service.ExternalSystemFacadeManager.a(ExternalSystemFacadeManager.java:178)
at com.intellij.openapi.externalSystem.service.ExternalSystemFacadeManager.doInvoke(ExternalSystemFacadeManager.java:133)
at com.intellij.openapi.externalSystem.service.ExternalSystemFacadeManager$MyHandler.invoke(ExternalSystemFacadeManager.java:270)
at com.sun.proxy.$Proxy57.getResolver(Unknown Source)
at com.intellij.openapi.externalSystem.service.internal.ExternalSystemResolveProjectTask.doExecute(ExternalSystemResolveProjectTask.java:48)
at com.intellij.openapi.externalSystem.service.internal.AbstractExternalSystemTask.execute(AbstractExternalSystemTask.java:137)
at com.intellij.openapi.externalSystem.service.internal.AbstractExternalSystemTask.execute(AbstractExternalSystemTask.java:123)
at com.intellij.openapi.externalSystem.util.ExternalSystemUtil$2.execute(ExternalSystemUtil.java:475)
at com.intellij.openapi.externalSystem.util.ExternalSystemUtil$3$1.run(ExternalSystemUtil.java:543)
at com.intellij.openapi.progress.impl.ProgressManagerImpl$TaskRunnable.run(ProgressManagerImpl.java:609)
at com.intellij.openapi.progress.impl.ProgressManagerImpl$7.run(ProgressManagerImpl.java:410)
at com.intellij.openapi.progress.impl.ProgressManagerImpl$3.run(ProgressManagerImpl.java:194)
at com.intellij.openapi.progress.impl.ProgressManagerImpl.a(ProgressManagerImpl.java:281)
at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:233)
at com.intellij.openapi.progress.impl.ProgressManagerImpl.runProcess(ProgressManagerImpl.java:181)
at com.intellij.openapi.application.impl.ApplicationImpl$10$1.run(ApplicationImpl.java:640)
at com.intellij.openapi.application.impl.ApplicationImpl$8.run(ApplicationImpl.java:405)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
at org.jetbrains.ide.PooledThreadExecutor$1$1.run(PooledThreadExecutor.java:56)
What can be the reason for this?
You should be able to work it around by setting the jdk from the settings not from the open/import project dialog.
From the welcome screen, go to Configure -> Project defaults -> Project structure and add the jdk.
Opening the sbt project should work well then.
Found solution from here
Another way to set JDK is from your current module/project settings (for your current project)
PickOpen Module Settings from project context menu (or default hit F4), then from left tab select Project and point correct Project SDK on dropdown.
The issue is usually caused by a wrong JDK version in ".idea/sbt.xml", e.g.:
<option name="jdk" value="1.7" />
This option is not updated accordingly when the Project SDK is changed, see SCL-10085. If you have the other JDK (1.7 in my example) generally configured, no error will occur, but the Project SDK will silently be changed back. Otherwise, this error occurs.
The problem can easily be resolved by manually editing the value in ".idea/sbt.xml" to the right JDK version.
Same error also occurs when you try to do a refresh in "SBT tasks".
Open
Preferences -> Language & Frameworks -> Scala Compiler Server
Turn on
Run compile server (in external build mode)
Once you done with refreshing the project, turn it off again to enable hotswapping back when you change your code in the editor.
I had to open Settings -> Language & Frameworks -> Scala Compiler Server
Then set the JVM SDK there, which was <No SDK>.
This was in addition to setting the Project SDK in Project Structure -> Project.
See the screenshot here.
IntelliJ 13.1.6 > File > Project Structure > set Project SDK
I got the same problem after I delete Java1.6 and Java1.7 from Project Settings(with Java8 as default).
Finally I solve the problem by change SBT JVM config to Custom Java(Settings -> Build, Execution, Deployment -> Build Tools -> SBT).
For me the above suggestions did not help for some reason. However, I did figure out that under Project Defaults > Project Structure (Welcome screen) my default Project SDK was set to the Go SDK.
What worked for me was setting this default SDK to the Java JDK.
For me, I had selected the JDK in "Open Module Settings" > Module > Dependencies > Module SDK.
However, SBT was looking for JDK at project level which is set in "Open Module Settings" > Project > Project SDK as #michasm has pointed out above
The latest Nightlies of the Scala plugin change how the project JDK is set, which should solve this in most cases. Let me know if it still breaks on some cases.
This happened to me in a multi-language project when my primary module's Project SDK was Python and I was trying to add a secondary module that was JDK (importing an sbt project).
I had to temporarily switch the primary module's Project SDK to JDK in order to add the sbt module. I then had the ability to go back and change each module to the correct SDK.

Undefined step definitions in IntelliJ

I'm trying to follow this article to match Cucumber specs with step definitions in IntelliJ.
When I press Alt+Enter, I see Inspection 'Undefined Step' options. However, I should see the intention action Create Step Definition.
I thought I had the Cucumber IntelliJ plugin installed, so that shouldn't be a problem. Any help is greatly appreciated.
Turns out I had the Gherkin plugin but not the Cucumber for Java plugin.
I wasted around an hour to solve this. My issue was, Idea was able to navigate from feature to step file. But when I wanted to execute one cucumber test from feature file (Right click and Run Scenario), it was giving error as undefined steps.
Solution: In the Edit Configuration -> provide the Glue for the cucumber which should be absolute path till steps folder. Please see below screen shot
This fixed my problem of running feature file from Idea.
Hope this helps others.
Most probably you need to install the cucumber for java plugin, if already installed then you need to enable from File>>Settings>>pugins.
I had to uncheck the "Create separate module per source set" checkbox under the "Build, Execution, Deployment" -> "Build Tools" -> "Gradle" settings, and then rebuild the project.
"Undefined" step error message would appear if you import a new BDD project.
This error could appear due to two reasons.
If you have not installed the "Cucumber for Java" plugin.
If you import any BDD projects then it will not detect step definition file.
Solution:
1. If the plugin is not found then you need to install from the below location.
File->Settings->Plugins->MarketPlace->Cucumber for Java
2. After Importing the project disable the plugin and enable once again in the Installed section under Installed.
For me there was a collision between Sidesteps plugin and Cucumber plugin in Intellij and as a result *.feature file extension was taken over by the Sidesteps plugin and was expecting Sidesteps step definitions ignoring Cucumber step definitions. No clue what Sidesteps actually is. So went to IntelliJ settings and reassigned the *.feature extension to Cucumber Scenario type and then everything worked fine and Cucumber steps are recognized by Intellij now.
I had the same issue where all of a sudden my feature to step definition glue was missing. All i did was goto Run->Edit Configurations->and removed the cucumber java
configuration and restarted IntelliJ. it worked fine.
I found that even with the Cucumber for Java plugin installed it was still generating only one step. I eventually uninstalled the Cucumber for Java plugin and reinstalled it and all step definitions were generated.
The issue was fixed after updating the Intelij to the latest version and after updating the cucumber and gherkin intelij plugins
Me not help not one of suggestions above.
But i find if you start one test from runner the problem goes on (it is worked if you have runner for some tests( Runner is class that have line #CucumberOptions(
features = "src/test/resources/stability_*****_features/",
glue = "steps"
)
And may be the next line in config helped you^
in configurations i put line: --plugin org.jetbrains.plugins.cucumber.java.run.CucumberJvm4SMFormatter
in Programm arguments line - it help me
If still not working, you can add runner class
add -> runner package -> Main Runner class
-test
-runner - Create this package
-stepPackage
-resources
-features
#CucumberOptions(features = {"classpath:features"}, glue = {"stepDefinition"},
monochrome = false,dryRun = false)
public class MainRunner extends AbstractTestNGCucumberTests {
}
That is it. Just run this class first. Right mouse click and Run'MainRunner'
Then it will work if you just go back and run Scenarios as well
I had the same issue and was resolved by going to Run> Edit configuration> Before Launch then click on the add option "+" and add Build Project option.
enter image description here