我试图用节点js将SVG转换为PNG.我的代码在这里:
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'image/png'});
var convert = child_proc.spawn("convert", ["svg:", "png:-"]),
values = (url.parse(req.url, true).query['values'] || ".5,.5")
.split(",")
.map(function(v){return parseFloat(v)});
convert.stdout.on('data', function (data) {
res.write(data);
});
convert.on('exit', function(code) {
res.end();
});
jsdom.env({features:{QuerySelector:true}, html:htmlStub, scripts:scripts, done:function(errors, window) {
var svgsrc = window.insertPie("#pie", w, h, values).innerHTML;
//jsdom's domToHTML will lowercase element names
svgsrc = svgsrc.replace(/radialgradient/g,'radialGradient');
convert.stdin.write(svgsrc);
convert.stdin.end();
}});
}).listen(8888);
Run Code Online (Sandbox Code Playgroud)
执行时我收到此错误(在MAC中)
events.js:72
throw er; // Unhandled 'error' event
^
Error: spawn ENOENT
at errnoException (child_process.js:980:11)
at Process.ChildProcess._handle.onexit (child_process.js:771:34)
Run Code Online (Sandbox Code Playgroud)
我已经为nodejs指定了路径.但我不知道它失败的原因.对这个问题有什么看法吗?
请找到以下示例代码,在Windows机器中正确显示的UTF-8字符.但是,它不适用于Linux机器(Ubuntu).
import javax.swing.JOptionPane;
public class JContPaneTest
{
public static void main(String[] args)
{
JOptionPane.showMessageDialog(null, "\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u304c\u898b\u3064\u304b\u308a\u307e\u305b\u3093\u3002\u30c7\u30fc\u30bf\u30d9\u30fc", "Error",JOptionPane.ERROR_MESSAGE);
}
}
Run Code Online (Sandbox Code Playgroud)
有什么方法可以解决这个问题吗?
有没有办法用java找到os名字?
我试过下面的代码,但它会返回看起来像(Linux,windows ..)
System.getProperty("os.name")
Run Code Online (Sandbox Code Playgroud)
我需要检测以下格式
Linux - "ubuntu,mandriva ..",windows - "xp,vista ......"
对不起我的英语不好 :-( !!!
任何的想法 ?
请检查下面的Java代码:
public class Test
{
public static void main(String arg[]) throws Throwable
{
Test t = new Test();
System.out.println(t.meth().s); //OP: Old value
System.out.println(t.meth().getVal()); //OP: String Implementation
}
private TestInter meth()
{
return new TestInter()
{
public String s = "String Implementation";
public String getVal()
{
return this.s;
}
};
}
}
interface TestInter
{
String s = "Old value";
String getVal();
}
Run Code Online (Sandbox Code Playgroud)
如您所见,我已匿名创建了一个界面.当我直接访问界面变量时,它将显示"旧值".
t.meth().s =>"旧价值"
通过getVal()方法访问它会返回正确的值,
t.meth().getVal()=>"字符串实现"
我不明白这段代码是如何工作的,有人可以向我解释一下吗?
以下代码适用于Firefox浏览器.但是,不是铬.下面的代码有什么问题?
window.onload = function()
{
document.body.onscroll = Test.callFn;
}
var Test = new function()
{
this.callFn = function()
{
console.log("Calling this function");
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢
我已按照 blog.gopheracademy.com/advent-2017/go-wasm 上的教程从 golang 语言生成 .wasm 文件。
我在执行程序时遇到以下错误,
/home/user/test >节点 wasm_exec.js test.wasm
RuntimeError: memory access out of bounds
at memchr (wasm-function[75]:96)
at internal_bytealg.IndexByteString (wasm-function[72]:24)
at runtime.findnull (wasm-function[683]:227)
at runtime.gostring (wasm-function[678]:126)
at runtime.goenvs_unix (wasm-function[604]:639)
at runtime.goenvs (wasm-function[432]:86)
at runtime.schedinit (wasm-function[498]:780)
at runtime.rt0_go (wasm-function[860]:165)
at _rt0_wasm_js (wasm-function[907]:71)
at global.Go.run (/home/user/test/wasm_exec.js:378:24)
Run Code Online (Sandbox Code Playgroud)
有时也会出现以下错误,
运行时:操作系统分配的内存[0x30000000,0x938ab2fd34000000)不在可用地址空间中:结束在可用地址空间之外
致命错误:内存预留超出地址空间限制
我使用了该程序默认的WebAssembly.Memory(默认内存约为1033MB)。
WebAssembly.instantiate(fs.readFileSync("test.wasm"), go.importObject).then((result) => {
process.on("exit", () => { // Node.js exits if no callback is pending
if (!go.exited) {
console.error("error: all goroutines asleep and no JavaScript callback …Run Code Online (Sandbox Code Playgroud) 以下代码有什么问题?它会在执行时抛出NullPointerException.
public class Test
{
public String method1()
{
return null;
}
public Integer method2()
{
return null;
}
public static void main(String args[])throws Exception
{
Test m1 = new Test();
Integer v1 = (m1.method1() == null) ? m1.method2() : Integer.parseInt(m1.method1());
}
}
Run Code Online (Sandbox Code Playgroud) 我在Redis中有两个列表.我如何检查这些列表是否相等?唯一的选择是从列表中逐个获取元素并与内存中的列表进行比较吗?
Redis是否提供任何解决方法?
为什么变量s不会被2改变
public class Test {
static void getVal(int s) {
s= 2;
}
public static void main(String arg[]) {
int s = 0;
getVal(s);
System.out.println(s);
}
}
Run Code Online (Sandbox Code Playgroud)