Scala NoClassDefFoundError related to Swing - swing

I have a GUI class named Gui.scala and Eclipse does not show any errors directly in the scala file. My Scala version is 2.11 and I have manually added scala-swing-2.10.4.jar to my build path in Eclipse. If I don't do this, Eclipse complains that it does not find the Swing library.
First lines of my source code look like this:
package filmreviews
import scala.swing._
import event._
import javax.imageio.ImageIO
import javax.swing.ImageIcon
import java.io.File
import java.awt.image.BufferedImage
import java.net.URI
import java.net.URL
import java.awt.Desktop
import java.awt.Cursor
import java.awt.Color
import javax.swing.border
import javax.swing.BorderFactory
import javax.swing.UIManager
object Gui extends SimpleSwingApplication {
def top = new MainFrame {
...more code here...
I get the following error:
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: scala/collection/GenTraversableOnce$class
Also, there is a long list telling where in code the error happened. Only lines referring to my own code are:
at filmreviews.Gui$$anon$3.<init>(Gui.scala:17)
at filmreviews.Gui$.top(Gui.scala:17)
at filmreviews.Gui$.top(Gui.scala:16)
This is why I think it is related to the creation of the MainFrame object. It can also be related to how I have manually added the Swing library to the build path. However, I don't know what causes the error or how to fix it.

If you're using Scala 2.11, you will need a version of scala-swing built for 2.11. 2.10.4 is binary incompatible with 2.11.
You can find the jar for a 2.11-compatible version on maven central.
Or for those using sbt:
libraryDependencies += "org.scala-lang.modules" %% "scala-swing" % "1.0.1"

Related

Avoid using web-only libraries outside Flutter web plugin packages

I'm building a Flutter app that I am trying to make work on the web. Part of it contains some web specific code:
import 'dart:html' as html;
import 'package:flutter/foundation.dart';
class DownloadViewModel extends ChangeNotifier {
static const String url = 'https://example.com/api/v1/app/myapp_1.0.0.apk';
void onAndroidDownloadPressed() {
html.window.open(url, 'AndroidApp');
}
}
However the dart:html import gives the following error:
Avoid using web-only libraries outside Flutter web plugin packages
The longer version of the warning looks like this:
Avoid using web libraries, dart:html, dart:js and dart:js_util in
Flutter packages that are not web plugins. These libraries are not
supported outside a web context; functionality that depends on them
will fail at runtime in Flutter mobile, and their use is generally
discouraged in Flutter web.
Web library access is allowed in:
plugin packages that declare web as a supported context
otherwise, imports of dart:html, dart:js and dart:js_util are disallowed.
And it's not just a warning. This actually prevents building an Android or iOS app (even though this method isn't accessible from non-Web Flutter apps).
The only solution I've figured out is to comment out the import when I am building for Android and iOS and then uncomment it when I am building for the web. Is there a better solution?
Use the universal_html package. It supports the browser, Dart VM, and Flutter and is a stand-in replacement for dart:html and other web related libraries.
dependencies:
universal_html: ^1.2.1
Then instead of using import 'dart:html' as html; you can use the following import:
import 'package:universal_html/html.dart' as html;
For those who came to this page for other related web import problems (like dart:js), this plugin also supports the following imports:
import 'package:universal_html/driver.dart';
import 'package:universal_html/html.dart';
import 'package:universal_html/indexed_db.dart';
import 'package:universal_html/js.dart';
import 'package:universal_html/js_util.dart';
import 'package:universal_html/prefer_sdk/html.dart';
import 'package:universal_html/prefer_sdk/indexed_db.dart';
import 'package:universal_html/prefer_sdk/js.dart';
import 'package:universal_html/prefer_sdk/js_util.dart';
import 'package:universal_html/prefer_sdk/svg.dart';
import 'package:universal_html/prefer_sdk/web_gl.dart';
import 'package:universal_html/prefer_universal/html.dart';
import 'package:universal_html/prefer_universal/indexed_db.dart';
import 'package:universal_html/prefer_universal/js.dart';
import 'package:universal_html/prefer_universal/js_util.dart';
import 'package:universal_html/prefer_universal/svg.dart';
import 'package:universal_html/prefer_universal/web_gl.dart';
import 'package:universal_html/svg.dart';
import 'package:universal_html/web_gl.dart';
Since the merge of Flutter-web into the main Flutter repository, it's no longer possible to directly add imports for web libraries (e.g. dart:html, or dart:js) in a Flutter project on the main channel when targeting Web, Android and iOS.
Use the universal html package which provides extensive support for multiple platforms and web libraries.
From the root level of your project, command
flutter pub add universal_html
import 'package:universal_html/html.dart' as html
This package isn't required to run some web files (e.g. dart:js). In my case, I just had to remove the import 'dart:js' import statement.

How to import a page within a page in Ionic 3

This is the app component. It gives an error that it can't find module pages/question/pages/question1/question1
This is the app module where I declared the question1. still the same error.
Your import path is wrong, it should be as,
import {question1} from './pages/questions/pages/question1'

Global AS3 File - FDT

I'm trying create a global file in AS3 with FTD.
It's a file that is imported by this code
<fx:Script source="../../../framework/util/util.as"/>
and is acessible by all classes in project.
Just like this without package or class.
import flash.events.MouseEvent;
import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.controls.dataGridClasses.DataGridColumn;
import mx.core.FlexGlobals;
import mx.core.UIComponent;
import mx.formatters.DateFormatter;
import mx.managers.ToolTipManager;
import mx.messaging.Channel;
import mx.messaging.events.ChannelEvent;
import mx.messaging.ChannelSet;
import mx.messaging.channels.AMFChannel;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.rpc.remoting.mxml.RemoteObject;
import mx.utils.ObjectUtil;
import spark.components.TitleWindow;
import spark.events.TitleWindowBoundsEvent;
private var channelSet:ChannelSet = new ChannelSet();
private var customChannel:Channel;
public function showErrorImmediately(target:UIComponent):void
{
// we have to callLater this to avoid other fields that send events
// that reset the timers and prevent the errorTip ever showing up.
target.callLater(showDeferred, [target]);
}
....
In FB this file works fine but when i migrate to FDT a lot of errors occurs.
Can anyone help me?
FDT does not support the source attribute for MXML script tags:
<fx:Script source="../../../framework/util/util.as"/>
Your code in file util.as is valid if you consider it as contents of a script block.
I assume you put the file util.as in some package in your source folder.
In this case FDT assumes it is a normal compilation unit. A normal compilation unit
has to start with a package and so FDT complains about that.
In general it is a bad practice to use the include statement or the source attribute and this is why FDT does not support that.
In your case I would consider defining your own abstract mxml component as base class of all your components containing the method and the fields.

Can't import sikuli modules from Sikuli IDE 1.0.0

I'm using Sikuli IDE 1.0.0 on Mac, trying to get a simple test case working where I call a script in one module from another.
The modules are all in the same directory.
testModule.sikuli just has this:
from sikuli import *
def testFunc():
exit(1)
testImport.sikuli just has this:
import testModule
reload(testModule)
testModule.testFunc()
running testImport just yields:
[error] ImportError ( No module named testModule )
on the import testModule line.
I've tried various additions to testImport including:
myScriptPath="[my project path]"
if not myScriptPath in sys.path: sys.path.append(myScriptPath)
None of these seem to work.
I think the import just brings the new functions into the same module.
Try calling testFunc() instead of testModule.testFunc().
I've encountered the same issue. I have solved this problem using classes.
Try this code:
testModule.sikuli:
from sikuli import *
class test:
def testFunc(self):
exit(1)
testImport.sikuli:
import testModule
foo = testModule.test()
foo.testFunc()
This should work assuming your files are in the same folder (for example ./test/testImport.sikuli and ./test/testModule.sikuli)

AS3 Access of undefined property error

I have code that reads a JSON file to import the information about a level in a game I'm making. The code was running and compiling fine until suddenly every time I tried to build, FlashDevelop started erroring "build failed" without actually giving an error.
I ran the code through the mxmlc compiler, to give me an error message, and it returned an error saying "Error: access of undefined property JSON" in line:
var level:Object = JSON.decode(json);
This is confusing because the JSON library is clearly included at the top of the file, "import com.adobe.serialization.json.JSON;", and this error started occurring completely on it's own, which is odd...
package
{
import flash.geom.Point;
import flash.geom.Rectangle;
import flash.utils.ByteArray;
import net.flashpunk.Entity;
import com.adobe.serialization.json.JSON;
public class LevelParser
{
public static function GetLevelByID(ID:int, source:Class):Level
{
// Store new entity
var populated:Vector.<Entity> = new Vector.<Entity>();
// Parse file into string
var bytes:ByteArray = new source();
var json:String = bytes.readUTFBytes(bytes.length);
var level:Object = JSON.decode(json);
// Find correct level
...
EDIT: Strangely if I comment out the line to call it, and this function, the code compiled fine in mxmlc, but in Flashdevelop is says "Build Failed" with no error
This is actually a reference error.
As of AS3 SDK 4.5, JSON became a native class within the SDK. In previous versions, you would have to download the adobe serialize classes to access JSON - which may be your issue.
When using the mxmlc, it will compile with all the included libraries specified in your sdk flex-config.xml. In FlashDevelop, it will only use the classes you include.
Solution: add the adobe serialize class to your project