Cannot resolve package from Scratch file

已回答

After updating this morning, my scratch file can no longer resolve packages in the project. I have tried invalidating caches and deleting .idea directory and re-importing pom.xml as suggested in other posts but this doesn't help.

There are no errors displayed in the editor and ctrl-b on the import statement correctly highlights the package in the project view panel.

 

IntelliJ IDEA 2019.1 (Community Edition)
Build #IC-191.6183.87, built on March 27, 2019
JRE: 1.8.0_202-release-1483-b39 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Windows 10 10.0

 

 

评论操作 固定链接

I have uploaded jn-2019-03-29-myframework.zip which is a simple project demonstrating my issue. If I create a scratch trying to access the 'Add' function in MyClass, I get an error that the package does not exist.

0
评论操作 固定链接

Works for me:

Make sure you have module classpath specified in the Run configuration as shown on the screenshot. Also try Build | Rebuild Project.

12
评论操作 固定链接

This has resolved the issue for me, thank you. Can I ask why this setting was changed between upgrading from the previous version though? I wouldn't have previously ever changed the classpath setting in the run configuration when I created the scratch and it was running fine until the upgrade to 2019.1.

3
评论操作 固定链接

The answer provided by @Serge Baranov is not working for me. I tried on different machines using the same gradle project.

After downgrading to 2018.3.6 everything is working again.

1
评论操作 固定链接

@Ts, here's what resolved it for me:

 

  1. Run -> Edit configurations 
  2. Select Java Scratch and then Scratch from the tree on the left
  3. Set 'Use classpath of module:' to your framework/project

I think initially Java Scratch wasn't selected for me and it was on the JUnit section so might be worth checking you have the Scratch selected in the tree view?

-2
评论操作 固定链接

Thank you for the steps 

0
评论操作 固定链接

Hi,
I upgraded again, this time to version 2020.1. Before that I removed everything related to Intellij in my home and install directory and even in the projects themselves. Unfortunately I still experience the same problem even though following the steps above, which btw. should be improved in any case as this is extremely confusing when no error is displayed in the editor. Why was the default to use the module classpath even changed in version 2019?

I tried to create a sample project. But there is nothing worth uploading. Even with a fresh project with a single class with one public static method, the method can not be called in my a scratch, build failing with 'can not find symbol'.

Please try creating multiple projects with different scratches, maybe also one with gradle like i did one my machine, to reproduce the error or give me a hint how I could help investigating this.

1
评论操作 固定链接

Do you see this error

Caused by: java.lang.ClassNotFoundException: Scratch

Similar to one of our bugs: https://youtrack.jetbrains.com/issue/IDEA-197627

1
评论操作 固定链接

Thanks Konstantin, that post describes the problem exactly: https://youtrack.jetbrains.com/issue/IDEA-197627#focus=streamItem-27-3920740.0-0

So yes, when IDEA-197627 is solved and scratches start working without the need to change any run configurations, this issue here would be fixed for me.

Thanks again for looking into this.

1
评论操作 固定链接

I can confirm this bug is still present in 2020.1.2. Also the ticket IDEA-197627 specifies Gradle, but in reality this bug affects Maven as well.

Any ETA on the fix? Java8 can't use the jconsole so if we cannot use scratches we basically cannot run/test/debug java snippets anymore and we are forced to downgrade.

1
评论操作 固定链接

>but in reality this bug affects Maven as well.

Do you have Settings (Preferences on macOS) | Build, Execution, Deployment | Build Tools | Maven | Runner | Delegate IDE build/run actions to Maven option enabled? If not, could you please provide a sample with the steps to reproduce at https://youtrack.jetbrains.com/issues/IDEA Thank you.

-1
评论操作 固定链接

I don't have delegate on (it just hangs if I enable that and try to run a scratch snippet). I've added the steps to reproduce it, which are none, just make a scratch and run it.

0
评论操作 固定链接

Most probably, the issue is caused by environment/settings, as we cannot reproduce that on our side. That is why we asking you to share your environment info and logs folder to https://youtrack.jetbrains.com/issues/IDEA

 

0
评论操作 固定链接

Still not resolved. Copying out the absolute path of the scratch file and replacing "Scratch" in the output in the failed run dialog and pasting it into the terminal does however work.

1
评论操作 固定链接

FWIW This is also happening for me in PyCharm as well. The code inspection is broken but I can run the file successfully.

0
评论操作 固定链接

I'm experiencing the same issue with a Kotlin scratch file. with the class path set to use the module class path and after a gradle build, It seems the scratch file can't find the classpath. There is no run configuration for this file. Any ideas?

0
评论操作 固定链接

Carl Furst What is the exact error you get? May you show the screenshot? 

0
评论操作 固定链接

I seem to be having the same problem with Webstorm.

0

请先登录再写评论。