Scala project using sbt throws NullPointerException - scala

I cloned the project from here, and tried to load it in Terminal by opening the directory and using the command sbt. But this shows error like this:
java.lang.NullPointerException
at java.base/java.util.regex.Matcher.getTextLength(Matcher.java:1769)
at java.base/java.util.regex.Matcher.reset(Matcher.java:416)
at java.base/java.util.regex.Matcher.<init>(Matcher.java:253)
at java.base/java.util.regex.Pattern.matcher(Pattern.java:1130)
at java.base/java.util.regex.Pattern.split(Pattern.java:1249)
at java.base/java.util.regex.Pattern.split(Pattern.java:1322)
at sbt.IO$.pathSplit(IO.scala:797)
at sbt.IO$.parseClasspath(IO.scala:912)
at sbt.compiler.CompilerArguments.extClasspath(CompilerArguments.scala:66)
...
...
I tried another project, pdffigures2. It shows similar error:
[info] Loading project definition from /path/to/project/pdffigures2/project
java.lang.NullPointerException
at java.base/java.util.regex.Matcher.getTextLength(Matcher.java:1769)
at java.base/java.util.regex.Matcher.reset(Matcher.java:416)
at java.base/java.util.regex.Matcher.<init>(Matcher.java:253)
at java.base/java.util.regex.Pattern.matcher(Pattern.java:1130)
at java.base/java.util.regex.Pattern.split(Pattern.java:1249)
at java.base/java.util.regex.Pattern.split(Pattern.java:1322)
at sbt.IO$.pathSplit(IO.scala:744)
at sbt.IO$.parseClasspath(IO.scala:859)
at sbt.compiler.CompilerArguments.extClasspath(CompilerArguments.scala:62)
at sbt.compiler.MixedAnalyzingCompiler$.withBootclasspath(MixedAnalyzingCompiler.scala:189)
...
...
and prompts me to retry, quit, last or ignore. I tried again, only to get the same result.
If it may help, I'm using Ubuntu 18.04.

I had java version 10.x and javac version 1.8x. I downgraded java version to 8, and the problem seems to have fixed

Related

Heroku error running Play: controllers/routes has been compiled by a more recent version of the Java Runtime

I am trying to run Play on Heroku...
The full error is:
play.api.UnexpectedException: Unexpected exception[RuntimeException: java.lang.UnsupportedClassVersionError: controllers/routes has been compiled by a more recent version of the Java Runtime (class file version 58.0), this version of the Java Runtime only recognizes class file versions up to 55.0] (58 is Java 14 and 55 is Java 11).
The Heroku help says:
Make sure you are using the correct JDK version by setting it in the system.properties file.
I added the following to system.proprties:
java.runtime.version=14.0.1.
And I can see it gets used by the Heroku compile. But I still get the error.
I thought that maybe the problem was the other way around so I also tried:
java.runtime.version=11.0.8
I also tried adding the following to application.conf
java.source=11.0.8
And for completeness java.source=14.0.1
When I run locally without Heroku (sbt compile stage) all is fine.
I have tried with the Play example from Heroku and also the Play example from Play (adding a procfile)... the result is the same.
The Play version is:
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.8.2")
I tried putting in some older versions but Heroku failed to compile.
I went back to trying to get the Heroku version to run locally (rather than the other way around). From the resulting error message I found that sbt installed via brew adds a dependency to JDK 13:
SBT fails with `String.class is broken`
I followed the fix listed there and installed sbt using SDKMAN (instructions here:
https://www.scala-sbt.org/1.x/docs/Installing-sbt-on-Mac.html)
This got me to the next error which was due to "old SBT version":
java.lang.NullPointerException in project root running sbt
After fixing this, I can now run Play on Heroku and locally

Compilation error in the Scala/Play example application for Heroku using Intellij

I am trying to compile the scala/Play framework example application on my local machine, but I am getting compilation errors when trying to compile using the SBT console in IntelliJ:
error: scala.reflect.internal.MissingRequirementError: object java.lang.Object in compiler mirror not found.
I also got this message in the event log related to different SBT versions:
14:48 Started sbt shell with sbt version 0.13.18 instead of 0.13.11 configured by project.
Update sbt version
Disable version override
Any suggestions on how to fix this?
For the first error
error: scala.reflect.internal.MissingRequirementError: object java.lang.Object in compiler mirror not found.
You might want to try and ensure that you are using a compatible java version. Like #cbley suggested, try making you are using version 8 of the JDK.
For the second error
14:48 Started sbt shell with sbt version 0.13.18 instead of 0.13.11 configured by project.
Update sbt version
Disable version override
Its just suggesting you update the version of sbt (which is most likely declared in your build.properties file in a folder called project. You can just search for it by double tapping shift in IntelliJ. But you are safe to ignore it if you cloned some example repository as well.
check

intelliJ multiple scala-library*.jar file

I tried to run scala app in IJ community version 2018.3.6, and ran into this error:
Error:scalac: Multiple 'scala-library*.jar' files (scala-library-2.12.8.jar, scala-library-2.12.8.jar) in Scala compiler classpath in Scala SDK sbt: org.scala-lang:scala-library:2.12.8:jar
and I checked hte .idea/libraries folder saw:
sbt__org_scala_lang_scala_library_2_11_8.jar.xml
sbt__org_scala_lang_scala_library_2_12_8.jar.xml
after I delete sbt__org_scala_lang_scala_library_2_11_8.jar.xml still got the same error, then i deleted all 2.11.8 scala*.files still got hte same error
I also tried to open the same project in IJ community version 2019.2.4, it complained:
Cannot determine module type ("SBT_MODULE") for the following module:
there is no 'sbt' tool listed in Preference -> Build, Execution, Deployment -> Build Tools
anyone know how to get it work?
## FIX
i ended up to uninstall and reinstall Scala plugin in IJ 2019.2.4 to get it working again.

play -help gives Error: Could not retrieve sbt 0.13.0: missing sbt.xMain

I created a new app using command play new hello and cd'ed into the directory. When I type play in the directory, I receive the following error:
akshay#Akshay:~/play/testn$ play -help
Java HotSpot(TM) Server VM warning: ignoring option MaxPermSize=512M; support was removed in 8.0
Getting org.scala-sbt sbt 0.13.0 ...
:: retrieving :: org.scala-sbt#boot-app
confs: [default]
0 artifacts copied, 43 already retrieved (0kB/45ms)
Error: Could not retrieve sbt 0.13.0: missing sbt.xMain
Play was working fine in my old Ubuntu box. Today only I got a fresh copy of Ubuntu 12.04 32 bit. I know it is error due to change in version, but certainly, I am not able to solve this. Please help me on this.
In checked .sbt/boot/update.log and I can see this :
trying http://repo.typesafe.com/typesafe/ivy-releases/org.sonatype.oss/oss-parent/7/jars/oss-parent.jar
tried http://repo.typesafe.com/typesafe/ivy-releases/org.sonatype.oss/oss-parent/7/jars/oss-parent.jar
HTTP response status: 404 url=http://repo.typesafe.com/typesafe/ivy-releases/org.sonatype.oss/oss-parent/7/jars/oss-parent.jar
CLIENT ERROR: Not Found url=http://repo.typesafe.com/typesafe/ivy-releases/org.sonatype.oss/oss-parent/7/jars/oss-parent.jar
typesafe-ivy-releases: resource not reachable for org.sonatype.oss#oss-parent;7: res=http://repo.typesafe.com/typesafe/ivy-releases/org.$
trying http://repo1.maven.org/maven2/org/sonatype/oss/oss-parent/
Though error was coming from a fresh ubuntu installation with oracle jdk 8, I tried completely removing jdk and then installing jdk 7, but still no solution. Since it was a fresh installation, I reinstalled ubuntu and installed jdk 7 and problem is solved. Not sure why is it contradictory to Play's recomendation of using Jdk 6 or above. Notifying Play Google Groups about this.
I was getting the same error while trying to build using sbt-launcher.jar which was invoked through jenkins. In my case there were two Scala versions within ~/.sbt/boot/ and removing the older version solved the issue.
I was trying to setup my development environment for one of our projects when I hit this issue. The problem was the sbt.version parameter in the build.properties file of our project which specifically mentioned the version of sbt as 0.13.8 and I had sbt 0.13.11.
After removing sbt 0.13.11 and installing 0.13.8, the issue got resolved. Or if it is possible for you to change the sbt version in your build.properties file, you can do that as well.

noClassDefFoundError using Scala Plugin for Eclipse

I successfully implemented and ran several Scala tutorials in Eclipse using the Scala plugin. Then suddenly I tried to compile and run an example, and this error came up:
Exception in thread "main" java.lang.NoClassDefFoundError: hello/HelloWorld
Caused by: java.lang.ClassNotFoundException: hello.HelloWorld
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:315)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:330)
at java.lang.ClassLoader.loadClass(ClassLoader.java:250)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:398)
After this point I could no longer run any Scala programs in Eclipse. I tried cleaning and rebuilding my project, closing and reopening my project, and closing and reopening Eclipse.
Eclipse version number 3.5.2 and Scala plugin 2.8.0
Here is the original code:
package hello
object HelloWorld {
def main(args: Array[String]){
println("hello world")
}
}
If you see this when you attempt to run as a Scala application then the most likely explanation is that your project didn't compile and no class files were generated. Please check whether or not that's the case: look in your project's output folder for hello/HelloWorld.class.
If your project didn't compile that could either be because there's an error which you've missed (and if this error isn't being reported in the Problems view that could be a bug, in which case please open a ticket on Trac) or because you've turned off automatic builds and not done a manual build of your project.
I had the same problem. Project doesn't compile but there are no errors highlighted and AFAIK the code is OK. It seems to be a problem with the Run Configurations.
Solution 1: Delete the existing Run Configuration for your object and create a new one
Solution 2: Create a new object and cut / paste all your code into that file
When running "clean" does not un-hose Eclipse, I next try saving my work, exiting Eclipse, and re-starting. That usually gets things going again, but not always. A few times I've had to update the Scala plugin with a more recent version (I'm using the latest nightly), to get things working again. I doubt that this worked because the new plugin happened to fix the bug, but rather expect that loading the new plugin gives the whole Eclipse-Scala
system a "total reset" that gets it unhosed.
I was getting this problem in a project that combined .java & .scala files.
The solution for me was:
Remove all .java files
Edit the scala code as needed so it compiles without them.
Add the .java files back in.
Edit the scala code back.
The other solutions given here didn't work for me. I tried: clean project, restarting Eclipse, closing-&-opening the project, creating a new .scala file. No joy.
I'm using Eclipse 3.7 (latest stable), Scala IDE 2.0.0 and Scala 2.9 on Ubuntu Linux 11.10.
The symptoms in my case were:
My project was working, but then it stopped compiling for no apparent reason. The IDE didn't show any compilation errors for .scala files, but there were no .class files in the output directory & I got a NoClassDefError if I tried to run anything.
If I created a deliberate error in a .scala file, that did get picked up as a compilation error.
The .java files were registering errors due to the missing scala classes.
I suppose there's probably a boot-strapping bug somewhere in the IDE plugin for .java/.scala mixes. I've done hybrid projects with this setup without problems, so it's only triggered in some situations. I don't know what the trigger is, but once triggered, there's no nice solution.
I had moved my one and only class/object/application to a package, but had not added the package declaration.
sbt compiled and ran fine; eclipse would not
Adding the package declaration at the top of the file fixed it.
Scala 2.8.3 plugin; no compile error
I encountered this error too but after doing the suggestions here (cleaning, deleting Run Configuration etc), I realized that I set the workspace wrongly that is why the class is not being found.
An indication that this is a problem is when the same error occurs when you try to compile a java project.
I encountered this error (compilation worked in sbt but failed in eclipse) when I created a new package object called "common". Deleting the package object in eclipse caused the compile error to go away. There was nothing in it.
I was using sbt-eclipse to build the eclipse project. I'm using scala eclipse 3.0.0-vfinal-20130326-1146-Typesafe.