I'm trying to encode something in my rails project into JSON, but it seems like any call to any JSON API in Rails causes WEBrick to throw a "Illegal Instruction" error.
My code was:
#nodes = Node.all
j = ActiveSupport::JSON
#json = j.encode(#nodes)
I don't understand why I get this error. Can someone please help?
Not sure if this is relevant, but I'm also using mysql2spatial adapter because my Node class contains a field with type GEOMETRY (mysql spatial extensions).
Thanks!
The JSON gem requires compiled extensions, so it's possible that your version isn't compiled for the architecture or OS you're currently using. You may want to re-install it and see if that resolves the problem.
Ruby itself rarely throws exceptions, but compiled extensions do this much more frequently, especially if compiled against a different set of system libraries.
Related
What's the difference between the Perl JSON modules below?
I have come across JSON::PP and JSON::XS. The documentation of JSON::PP says it is compatible with JSON::XS. What does that mean?
I am not sure what the difference between them are, let alone which of them to use. Can someone clarify?
Perl modules sometimes have different implementations. The ::PP suffix is for the Pure Perl implementation (i.e. for portability), the ::XS suffix is for the C-based implementation (i.e. for speed), and JSON is just the top-level module itself (i.e. the one you actually use).
As noted by #Quentin, this site has a good description of them. To quote:
JSON
JSON.pm is a wrapper around JSON::PP and JSON::XS - it also does a bunch of moderately crazy things for compatibility reasons, including extra shim code for very old perls [...]
JSON::PP
This is the standard pure perl implementation, and if you're not performance dependent, there's nothing wrong with using it directly [...]
JSON::XS
Ridiculously fast JSON implementation in C. Absolutely wonderful [...]
As you can see, just installing the top-level JSON module should do it for you. The part about compatibility just means that they both do the same thing, i.e. you should get the same output from both.
I installed the Perl JSON module a few years ago on a RHEL server I managed and it was a really straightforward process: just install (or build) the module from the CPAN site and you're done.
Installing should be a simple case of either using the OS package manager (if in GNU/Linux), using the cpan utility, or building from source. The OS package manager is recommended, as it helps keep things updated automatically.
To verify that it's installed, just try the following command from the terminal (assuming GNU/Linux):
$ perl -e 'use JSON;'
If it doesn't complain, then you should be good to go. If you get errors, then you should get ready to go in an adventure.
You can install JSON module, cpan install JSON
use JSON;
my $result = from_json($json);
if($result->{field})
{
# YOUR CODE
};
How can I fix that:
Command:
$ ceylon format source/com/example/helloworld/*
Exception:
Exception in thread "main" java.lang.NoSuchMethodError: ceylon.language.runtime_.getMaxArraySize()Lceylon/language/Integer;
at ceylon.collection.Hashtable.<init>(Hashtable.ceylon:35)
at ceylon.collection.Hashtable.<init>(Hashtable.ceylon)
at ceylon.collection.HashMap.$default$hashtable(HashMap.ceylon:31)
at ceylon.formatter.options.Spaces$cache_.<init>(IndentMode.ceylon:62)
at ceylon.formatter.options.Spaces$cache_.<init>(IndentMode.ceylon)
at ceylon.formatter.options.Spaces.<init>(IndentMode.ceylon:59)
at ceylon.formatter.options.FormattingOptions.$default$indentMode(FormattingOptions_generated.ceylon:355)
at ceylon.formatter.options.FormattingOptions.<init>(FormattingOptions_generated.ceylon)
at ceylon.formatter.options.loadProfile_.loadProfile(profiles.ceylon:79)
at ceylon.formatter.options.loadProfile_.loadProfile(profiles.ceylon)
at ceylon.formatter.options.commandLineOptions_.commandLineOptions(formattingOptions.ceylon:125)
at ceylon.formatter.options.commandLineOptions_.commandLineOptions(formattingOptions.ceylon)
at ceylon.formatter.run_.run(run.ceylon:285)
...
I think I have to re-install the formatter. But which version?
For no reason the following command works:
ceylon run ceylon.formatter source/com/example/helloworld/*.ceylon
Where is the difference and how can I fix it.
ceylon.language.runtime used to be implemented in hand-written Java code. In this code, getMaxArraySize() accidentally returned ceylon.language.Integer when it should have returned long. This worked, but wasn’t quite correct.
Then, with native support in Ceylon 1.2, runtime (along with some other objects) were rewritten as native Ceylon code. Since this is converted to Java by the Ceylon compiler, the method now gets the correct return type, long. Newly compiled modules will now call this method, but code that was compiled against an old ceylon.language will still try to call a method returning ceylon.language.Integer, which leads to your NoSuchMethodError.
What’s happening here, it seems, is that ceylon format runs ceylon.formatter/1.1.0, which was compiled against ceylon.language/1.1.0, and now can’t run with ceylon.language/1.2.0. ceylon run ceylon.formatter probably runs ceylon.formatter/1.2.0 for some reason, which works.
I’m not sure what you need to do to fix this. I changed the way the ceylon format plugin works recently, so you probably need to delete the old ceylon format script (a ceylon-format or ceylon-format.bat file somewhere in .ceylon/bin, I believe). Hopefully the new one is already there, ready to take over.
Try ceylon plugin uninstall format and see if that fixes things.
A second option would be to say ceylon plugin install ceylon.formatter/1.2.0
The reason why ceylon format doesn't work but ceylon run does is because your installed ceylon format will look for the hard-coded version 1.1 which isn't compatible anymore while ceylon run will look for any version that's compatible with the current Ceylon version you're using. (So it will find both 1.1.0 and 1.2.0 but it will discard 1.1.0 because it isn't compatible and therefore choose 1.2.0 automatically)
I am using Robotlegs to create a simple application in as3, which I have been using for a couple of months now. I seem to be getting an injection error when injecting the ISignalCommandMap into my config file, which has only started happening after I moved my application from one computer to another. It may be to do with conflicting libraries, but I have re-downloaded the newest versions of everything. I am also using starling in the application, but everything was working on the other computer.
Here is the error I am getting
Injector is missing a mapping to handle injection into property "commandMap" of object "[object Config]" with type "Config::Config". Target dependency: "robotlegs.bender.extensions.signalCommandMap.api::ISignalCommandMap|"
Any thoughts to why this has started happening?
What solved this for me was extending MVCSBundle like in this example project and then using that class in place of MVCSBundle.
After quite a bit of searching and trying different things, I am stumped on how to get mym to work (as found here: http://sourceforge.net/projects/mym/). I was wondering if anyone has a very simple list of actions needed to get this to work. I think my main trouble is installing zlib. I don't understand how to actually install it or work with it. I have tried to use Microsoft Visual C++ Express 2010 but then only the debug versions are compiled. That means when I try to use the mex function in matlab it gives me the error:
Error: Could not detect a compiler on local system
which can compile the specified input file(s)
I just don't understand the process and everywhere I look it says something different. I have tried multiple versions of each all of the programs involved and nothing seems to work. Any help would be greatly appreciated.
Do:
mex -setup
from the command line to define your compiler on your system. Once you do that then Matlab will correctly locate the compiler and build the mex libraries it needs.
See:
http://www.mathworks.com/help/matlab/matlab_external/building-mex-files.html
After installing jdk 7 and switching java platform for my project in ide i get this when im trying to build project.
warning: [options] bootstrap class path not set in conjunction with -source 1.6
An annotation processor threw an uncaught exception.
Consult the following stack trace for details.
java.lang.NoSuchMethodError: com.sun.tools.javac.util.Name$Table.instance(Lcom/sun/tools/javac/util/Context;)Lcom/sun/tools/javac/util/Name$Table;
at uk.org.retep.util.javac.JavacUtils.<init>(JavacUtils.java:128)
at uk.org.retep.util.annotation.AnnotationScannerProcessor.process(AnnotationScannerProcessor.java:76)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:793)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:722)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.access$1700(JavacProcessingEnvironment.java:97)
at com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1029)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1163)
at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1106)
at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:824)
at com.sun.tools.javac.main.Main.compile(Main.java:419)
at com.sun.tools.javac.main.Main.compile(Main.java:333)
at com.sun.tools.javac.main.Main.compile(Main.java:324)
at com.sun.tools.javac.Main.compile(Main.java:76)
at com.sun.tools.javac.Main.main(Main.java:61)
I know that sun switched some apis or something, but ide doesnt tell me whats wrong exactly. Thanks in advance.
You should really share your code that's causing the exception, but the exception indicates that you're using an internal Java API (any class contained in the com.sun packages). You shouldn't be using those APIs directly, as they're considered private implementations and subject to change. As those APIs are private, it isn't as simple as looking for the Javadoc to see what methods are available, but suffice it to say that the method you're calling doesn't exist. You have a few options:
If you're calling this method directly, you need to refactor. You should look for ways to accomplish the same work using public APIs.
If this happens after calling a library method, you should file a bug with the library maintainer informing them about the error and the risks of using the com.sun APIs.
If this happens after calling a public Java API (anything in the java or javax packages) then You should file a bug report with Oracle. This one seems unlikely though.
Also, if you share your code, we may be able to better help you.
[edit]
Further, see this page for more information about why you shouldn't use classes in the com.sun packages.