I just begin to use Dart, and I'm wondering why my first app doesn't work.
void main() { print("Hello, World!");}
When I run the app, I get this error message:
dart --enable-checked-mode HelloWorld.dart
Dart_NewString expects argument 'str' to be valid UTF-8.
I'm new, I follow the tutorial on the website http://www.dartlang.org/docs/editor/getting-started/#code And Hello World doesn't work -_-
Can some one help me?
I suspect the file is not encoded in UTF-8.
Try changing the file encoding to UTF-8 and retry.
import 'dart:html';
num rotatePos = 0;
void main() {
query("#text")
..text = "Click me!"
..on.click.add(rotateText);
}
void rotateText(Event event) {
rotatePos += 360;
query("#text").style
..transition = "1s"
..transform = "rotate(${rotatePos}deg)";
}
Related
Anyone have a canned solution for integrating SASS or another CSS preprocessor into the Dart editor? Seems to require a custom build.dart, which I would rather copy than code. Thanks.
I stumbled upon this a few days ago
Sass integration for pub
Here is a build.dart file with basic support for SASS:
import 'dart:io';
void main(List<String> args) {
for (String arg in args) {
if (arg.startsWith('--changed=')) {
String file = arg.substring('--changed='.length);
if (file.endsWith('.scss')) {
var result = Process.runSync('sass',
[ '--line-numbers', file,
file.substring(0, file.length - '.scss'.length) + '.css']);
if (result.exitCode != 0) {
// report error (SASS seems to only report first error)
// split error lines
var lines = result.stderr.split('\n');
// escape quotes in error message on first line
var error = lines[0].replaceAll('"', r'\"');
// extract line number from second line
var numMatch = new RegExp(r'\d+').firstMatch(lines[1]);
var lineNum = numMatch == null ? 1 : num.parse(numMatch.group(0));
// Report error via JSON
print('[{"method":"error","params":{"file":"$file","line":$lineNum,"message":"$error"}}]');
}
}
}
}
}
During development (with Dart Editor or another editor...), just use sass the way it's meant to be used, in your directory project :
sass -w .
Put the CSS generated files in the ignore list of your source code management system (aka .gitignore for git).
And for dart2js compilation, use the sass pub package : http://pub.dartlang.org/packages/sass
I am facing an issue with returning any type of array with .jcall(). Here is my code.
public class Test(){
public static double[] sample(){
double[] nobjarr = new double[5]
nobjarr[0] = 1.0;
nobjarr[1] = 1.0;
nobjarr[2] = 1.0;
nobjarr[3] = 1.0;
nobjarr[4] = 1.0;
return nobjarr;
}
}
In R, I am calling using .jcall
library(rJava)
.jinit()
.jaddClassPath("path to .class file")
objT <- .jnew("Test")
res <- .jcall(objT,"[D","sample")
For this I get an error saying "Error in .jcall(objT, "[D", "sample") :method sample with signature ()[D not found"
Have you tried something like this:
Test <- J( "Test" )
Test$sample()
This uses the reflection based API that is in rJava for several years now and is much more convenient than the low level .jnew, .jcall interface.
I don't know rJava, but it looks like you were telling the library to look for an instance method when the method is actually static. Check the documentation to see what the first argument to jcall should be for a static method.
I'm a beginner of both gtk and GtkD.
Now, I'm trying to get input from keyboard with reference to this .
But, It seems that three years have made some changes in Toolkits.
I wrote code below. However, I got strange values of ev in callback function.
I could not see any prospect of resolution with going alone.
So, could you show me where to modify?
I appreciate you in advance, and also your patient with my poor English.
I'm using gtkD-2.1.1 and gtk+3.2.3.
this is the full code:
import std.stdio;
import gtkc.gdktypes;
import gtk.MainWindow;
import gtk.Widget;
import gdk.Event;
import gtk.Main;
class Window : MainWindow{
immutable width = 200;
immutable height = 200;
this(){
super("input test");
setDefaultSize(width,height);
setEvents(EventMask.KEY_PRESS_MASK); // Actually I don't know how this works
auto callback_func = cast(bool delegate(Event,Widget))&get_key; // I doubt this cast
this.addOnKeyPress(callback_func);
showAll();
}
bool get_key(GdkEventKey* ev, Widget widget){
writefln("sender %s", widget);
writefln("type %x",ev.type);
writefln("window* %x",ev.window);
writefln("send_event %x",ev.sendEvent);
writefln("time %x",ev.time);
writefln("state %x",ev.state);
writefln("keyval %x",ev.keyval);
writefln("length %x",ev.length);
writefln("gchar* %x",ev.string);
writefln("hardware_keycode %x",ev.hardwareKeycode);
writefln("group %x",ev.group);
writefln("is_modifier %x\n",ev.bitfield0);
return true;
}
}
void main(string[] args){
Main.init(args);
auto win = new Window();
Main.run();
}
Yes, that cast is wrong. I guess that Signature with GdkEventKey* is outdated. Change your get_key to take an Event and you should get proper results:
...
auto call = &get_key;
...
bool get_key(Event e, Widget widget){
GdkEventKey* ev = e.key();
...
I have never done anything with GtkD, and this is just the result of some glances over the docs. So, it's probably not best practice, but it should get you back on the road.
All:
I am running Windows XP (32 Bit) with 32 Bit Java and 32 Bit OpenCV 2.4.3. When I attempt to capture a video frame from an AVI with following code in Eclipse:
import com.googlecode.javacv.FrameGrabber.Exception;
import com.googlecode.javacv.OpenCVFrameGrabber;
public class FrameReader
{
public static void main(String[] args) throws Exception,
InterruptedException
{
OpenCVFrameGrabber grabber = new OpenCVFrameGrabber("hall_gray.avi");
grabber.start();
grabber .release();
return;
}//End method
}//End class
The following error happens:
========================== Start of Error =========================
A fatal error has been detected by the Java Runtime Environment:
EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x77c46fa3, pid=4776, tid=3392
JRE version: 7.0_02-b13
Java VM: Java HotSpot(TM) Client VM (22.0-b10 mixed mode, sharing windows-x86 )
Problematic frame:
C [msvcrt.dll+0x36fa3]
Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
An error report file with more information is saved as:
C:\Java Projects\JavaCVTester\hs_err_pid4776.log
If you would like to submit a bug report, please visit:
http://bugreport.sun.com/bugreport/crash.jsp
The crash happened outside the Java Virtual Machine in native code.
See problematic frame for where to report the bug.
==================== End of Error Message ==================
Could someone help me out on this issue?
Thanks in advance.
Try to reinstall your jre.
Also goto the windows startup & recovery option. Choose "writing debugging option" to "Complete memory dump".
The OpenCVFrameGrabber does not support many video formats. The error message "[...] Problematic frame: C [msvcrt.dll+0x36fa3] [...]" probably points out, that your video format may not be supported.
The FFmpegFrameGrabber is more flexible. Try the following code:
import com.googlecode.javacv.FFmpegFrameGrabber;
import com.googlecode.javacv.FrameGrabber;
import com.googlecode.javacv.FrameGrabber.Exception;
public class FrameReader {
public static void main(String[] args) throws Exception {
FrameGrabber grabber = new FFmpegFrameGrabber("hall_gray.avi");
grabber.start();
grabber.release();
return;
}
}
In JavaCV, you can use FFmpegFrameGrabber which is a wrapper of OpenCVFrameGrabber and it has a lot of methods rather than OpenCVFrameGrabber.
Try the following code to extract and save the frames from the video:
import java.io.File;
import com.googlecode.javacv.FFmpegFrameGrabber;
import com.googlecode.javacv.Frame;
import com.googlecode.javacv.cpp.opencv_core.IplImage;
import static com.googlecode.javacv.cpp.opencv_highgui.cvSaveImage;
public class Getting_Frames
{
public static void main(String[] args) throws Exception
{
File f = new File("example.avi");
FFmpegFrameGrabber grabber = new FFmpegFrameGrabber(f);
try {
grabber.start();
} catch (com.googlecode.javacv.FrameGrabber.Exception e1) {
}
long frameLength = grabber.getLengthInFrames();
int increment = (int) Math.ceil(frameLength / 30);
if (frameLength < 30) {
System.err.println("Not enough frames");
}
// To grab frames per 30 seconds
Frame[] s_frame = new Frame[1000];
for (int i=0, frame_counter = 0; i < frameLength; frame_counter++) {
if((frame_counter % 2000 )==0)
{
s_frame[i]=grabber.grabKeyFrame();
IplImage temp = s_frame[i].image;
System.out.println(temp.nChannels()+" "+temp.origin()+" "+temp.highValue());
cvSaveImage(i+"new.jpg",temp);
i++;
}
}
// To know number for each video
System.out.println(frameLength);
}
}
I write the code in I/O Kit Driver template in the following way:
#include <IOKit/IOService.h>
class com_osxkernel_driver_IOKitTest : public IOService
{
OSDeclareDefaultStructors(com_osxkernel_driver_IOKitTest)
public:
virtual bool init (OSDictionary* dictionary = NULL);
virtual void free (void);
virtual IOService* probe (IOService* provider, SInt32* score);
virtual bool start (IOService* provider);
virtual void stop (IOService* provider);
};
#include "IOKitTest.h"
#include <IOKit/IOLib.h>
#define super IOService
OSDefineMetaClassAndStructors(com_osxkernel_driver_IOKitTest, IOService)
bool com_osxkernel_driver_IOKitTest::init (OSDictionary* dict)
{
bool res = super::init(dict);
IOLog("IOKitTest::init\n");
return res;
}
void com_osxkernel_driver_IOKitTest::free(void)
{
IOLog("IOKitTest::free\n");
super::free();
}
IOService* com_osxkernel_driver_IOKitTest::probe (IOService* provider, SInt32* score)
{
IOService *res = super::probe(provider, score);
IOLog("IOKitTest::probe\n");
return res;
}
bool com_osxkernel_driver_IOKitTest::start (IOService *provider)
{
bool res = super::start(provider);
IOLog("IOKitTest::start\n");
return res;
}
void com_osxkernel_driver_IOKitTest::stop (IOService *provider)
{
IOLog("IOKitTest::stop\n");
super::stop(provider);
}
When I build this code, I get four errors:
Expected function body after function declarator
stray '\357' in program
stray '\277' in program
stray '\274' in program
Can you see the error?
Can you see the error?
No. But the compiler can. And Xcode will show it to you.
I pasted your code into a new project and did compile it:
All three stray characters are in the same part of the code.
If such a stray '\something' error happens you have a character in your code that can't be compiled, and you usually can't see them. They often come from a copy and paste that went wrong.
Just delete the line with the error and write it again. Don't copy and paste or anything.
I took that part of the code and opened it in a hex editor. So you can see where these errors come from.
For anyone that uses KATE (KDE Advanced Text Editor), I was able to fix similar 'stray errors' by opening up the files causing the error and Unchecking the "Add Byte Order Mark (BOM)" option which can be found under the Tools menu. The file will not appear to have been changed after you uncheck this setting so you will need to actually save (Ctrl+S) the file. When you re-compile, the error will be gone.