import scala.swing._ in eclipse giving an error that it is not a member of package scala - eclipse

Does anybody have any experience with trying to get swing to work in eclipse, I can import it fine into scala using the command line interface, but when i try and use it in an eclipse scala project I get the following error:
import scala.swing._
"object swing is not a member of package scala"
Any help would be much appreciated.

If you are missing the library (as RĂ¼diger said, it is a separate dependency now), you can find how to add it to your build system here (for Scala 2.11):
http://search.maven.org/#artifactdetails|org.scala-lang.modules|scala-swing_2.11|1.0.1|bundle
Look under "Dependency Information", e.g. for sbt if you use that.

Related

How to add Breeze to Scala project in Eclipse?

I am new to Scala and I am trying to import a Scala project into Eclipse IDE. I am getting this error:
not found: object breeze.
The line of the error is:
import breeze.linalg._
I have added the breeze.jar but the problem is not resolve. Can anybody help me how I can fix this problem?
Breeze has a lot of dependencies, and so you're better off using SBT or Maven to manage dependencies for you. If you insist, I'd recommend following the directions for adding a Maven dependency directly to Eclipse (see, e.g., How do I add a "maven dependency" in eclipse?)
And then add a dependency on breeze_2.11 version 0.11 (or _2.10 if you use scala 2.10)

import scala.io.StdIn

I'm using Eclipse ScalaIDE and for some reason I'm not able to
import scala.io.StdIn
I'm getting a red squiggly that tells me:
object StdIn is not a member of package io
And I'm seeing that it's not in that scala.io jar file. The ScalaDoc, however says it should be there. I've tried both scala 2.10.4 and 2.11.5. I've used the Eclipse ScalaIDE to create the scala project and I've also created an sbt eclipse project directly using the scalasbt.plugin which I use all the time to manage ScalaIDE dependencies.
sbt "eclipse with-source=true"
Neither way is getting it.
I'm currently taking the Coursera Reactive Programming course and an assignment file has this import. I'm able do compile the project with sbt directly, but Eclipse ScalaIDE is not doing the job. Any clues? There may be good reason why not to use scala.io.StdIn, but my question is why can I not get it to import in the ScalaIDE?
thank you
scala.io.StdIn is new in scala 2.11.x and does not exist in previous versions.
The problem you are likely encountering is that ScalaIDE is not picking up the scala version you are specifying. Since you say that you tried it with 2.10.4, it probably still has that cached or set somewhere and it's failing because it cannot find the specified class.

Scala eclipse plugin java.lang.ClassNotFoundException

I am using eclipse Version: 3.7.2 with the Scala IDE for Eclipse 2.1.0.nightly-2_09-201203121521-6e8582e. The java version is 1.6.0_31. The OS is Ubuntu 11.10.
I have looked for solutions to this problem, but I have not found one yet. I hope there is not an obvious answer that I have missed.
I have this class (note the package):
package model.x.y
import org.scalatest.FunSuite
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
#RunWith(classOf[JUnitRunner])
class GibberishTestSuite extends FunSuite {
test("Check Gibberish") {
assert("blah" === "blah")
}
}
I am also using gradle and the source path looks like this (note that the package does not match the directory hierarchy):
.../src/test/scala/model/GibberishTest.scala
Eclipse and gradle generate the coresponding class files:
bin/model/x/y/GibberishTestSuite.class
build/classes/test/model/x/y/GibberishTestSuite.class
This runs fine through gradle, but when I try to run in eclipse, I get
Class not found model.GibberishTestSuite
java.lang.ClassNotFoundException: model.GibberishTestSuite
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
If I change the package to
package model
so that the directory hierarchy and the package name match, then I am able to run the unit test in eclipse. In scala, it is legal for the package structure and the directory structure not to match. However, the mismatch seems to be confusing eclipse or the plugin.
Am I doing something wrong? Am I missing some configuration nuance? Is this scala language feature not supported in eclipse? Will it be supported at some point?
Thank you.
This is an Eclipse (JDT) problem rather than a Scala/scala-ide problem.
There was a bug raised against Eclipse (Package Explorer tree does match declared package), but basically, Eclipse assumes that the hierarchy matches the package names. This will be fixed eventually in the Scala-ide, but the model needs to be changed, to remove the dependency on the JDT. If you want this fixed, it's a good idea to add your vote to the above issue.

"is not a member of package" error when importing package in Scala with SBT

(Relative beginner here, please be gentle...)
I've got a Scala program that I can build with sbt. I can (from within sbt) run compile and test-compile with no errors. I've defined a package by putting package com.mycompany.mypackagename at the top of several .scala files. When I do console to get a Scala REPL, this happens:
scala> import com.mycompany.mypackagename._
<console>:5: error: value mypackagename is not a member of package com.mycompany
import com.mycompany.mypackagename._
Any variation of this also fails. When I just do import com.mycompany I get no problems.
I thought that running the Scala console from within sbt would properly set the classpath based on the current projects? What (completely obvious) thing am I missing?
I ran into this same problem, and then I realized I was running scala 2.10.0 on commandline, and IDEA was using Scala 2.9.2. So the fix was to change both to use the same version, and:
sbt clean
What will happen if you import actual class name instead of wildcard.
import com.mycompany.mypackagename.ActualClassName

Bad class file error when using Scala 2.8.x (2.8.0 and 2.8.1) in Javafx 1.x (1.2 and 1.3.1)

When trying to import scala.Option in a javafx script, I get the following javafxc error:
cannot access scala.Option.$anonfun$orNull$1
bad class file: scala/Option$$anonfun$orNull$1.class(scala:Option$$anonfun$orNull$1.class)
undeclared type variable: A1
Please remove or make sure it appears in the correct subdirectory of the classpath.
import scala.Option;
I am using Scala 2.8.1, Javafxc 1.3.1_b101, JVM 1.6.0_21-b06, OS Ubuntu 10.10. The same code was working in Scala 2.7.7 .
Later edit:
The same error is reported in case I import scala.immutable.Seq/List/Traversable/Iterable . I have tried the imports in a default Netbeans 6.9.1 JavaFX project which has in the classpath only scala-library.jar.
It reminded me first of #4067, but this one looks quite different.
I would suggest that you try to reproduce the error with 2.8.1 or 2.9 trunk, maybe it is fixed?