I am trying to run some code in a Scratch java file, from IntelliJ IDEA, but once I add a class in my project and try to run it, I get the following error:
Error:(1, 45) package com.example does not exist
Error:(11, 9) cannot find symbol
symbol: class MyClass
location: class Scratch
How can I use my project's classes in a Scratch file?
Make sure the Scratch Run configuraiton has the module, which has these classes defined, specified in Use classpath of module drop-down list:
Select the required module from the drop down list in Use classpath of module(as answered by #Andrey)
Now got to Build then select Build Project or Rebuild Project.
These two steps helped me to resolve the issue.Hope it helps you too !
Related
I am using IntelliJ IDEA 2021.1 (Community Edition) - Build #IC-211.6693.111, built on April 6, 2021.
I created a new kotlin project - project template(JVM): Application, built system: Gradle Kotlin,
project JDK:1.8 version 1.8.0_281.
In the “scr/main/kotlin” folder, I created a kotlin file with a simple code like "fun main(){println(“Hi!”)}.
When I tried to run the file(the build was ok), I got this error: “Could not find or load main class MyAppKt”.
What did I do wrong?
Did you also add your main class to the build.gradle file?
mainClassName = "projectPackage.MyAppKt"
I assume if you are adding the MyAppKt file manually it is not added to the build.grale. But clearly more information about the project would help here. Meanwhile check this post Kotlin - Error: Could not find or load main class _DefaultPackage
In a newly installed IntelliJ IDEA, I created a new Kotlin scratch file and tried to run it, but it gives me an error:
add kotlin script runtime jar to classpath
There is related issue on YouTrack: https://youtrack.jetbrains.com/issue/KT-33010
As a workaround you could add kotlin runtime manually:
Open "Project Structure | Modules"
Select your module, click on plus and add "Kotlin" facet
See "kotlin library not found ..." message and click on "Fix..."
Select your module in editor ( "Use casspath of module").
Just add one line of dependency
dependencies {...implementation("org.jetbrains.kotlin:kotlin-script-runtime:1.5.21")...}
Not sure if there's any magical trick that sorted this out, but I simply created a new Scratch file and everything worked!
PS: In my case, I suspect the problem was related to me renaming the scratch file previously. Again, not sure! :)
When I run the program, the following window opens
What's the matter? I had this package in all previous projects and there were not any problems
You need to define a module which classpath should be used for that run configuration - Use classpath of module setting
I am trying to compile openjdk-7 source code on Ubuntu 14.04:
export LANG=C ALT_BOOTDIR=/usr
make all
I saw some errors like:
symbol: class ClassNotFound
location: class CompoundType
../../../../src/share/classes/sun/rmi/rmic/iiop/CompoundType.java:1299: error: cannot find symbol
These missing classes are all in the package named sun.tools.java. I suspect these are some nonstandard libs required by the jdk build process. However I cannot find relevant information in online build tutorials. So what are these missing classes and how I can fix them?
Thanks.
Some applications need the tools.jar from the JDK which has these packages. This is often used for runtime compilation of generated code. Add this to the class path from your JDK.
Note: these are not package you would normally pass via RMI however. I would have a look at the classes to see why it would need to do this.
I just started learning Javafx with Java11
I created a project in IntelliJ and it gave the standard structure.
In src file when I change the package name for the package "sample" to anything else, IntelliJ gives the following error.
Error:Kotlin: The Kotlin standard library is not found in the module graph. Please ensure you have the 'requires kotlin.stdlib' clause in your module definition
The error disappears when I refactor the package back to "sample".
how do I rename without getting this problem.
this might be helpfull
Javac gives this error, when lint is enabled and you use Java 9 module in Kotlin. You have to declare "requires kotlin.stdlib" in your module-info.java.
Ran into the same issue. For me, I'm using a module-info file in the src folder that looks like this:
module javafx {
requires javafx.fxml;
requires javafx.controls;
requires javafx.graphics;
opens sample;
}
If you rename your package to foo, then you need to change the last line to "opens foo". Otherwise it's still gonna look for and try to open a package named "sample". I have no idea what this has to do with kotlin.
I had the same problem and I solved it disabling "Kotlin migration detection". I have already response here:
https://stackoverflow.com/a/59628873/2350799
I had the same problem. But as long as you are not using Kotlin in the project there is a workaround : disable the Kotlin plugin, under settings.