小编Jak*_*r00的帖子

java如何用负数进行模数计算?

我做模数错了吗?因为在Java -13 % 64中应该评估,-13但我得到51.

java math modulo negative-number

89
推荐指数
5
解决办法
11万
查看次数

条件表达式的类型不能确定为

当我在MonoDevelop中编译我的C#项目时,我收到以下错误:

Type of conditional expression cannot be determined as 'byte' and 'int' convert implicitly to each other

代码片段:

byte oldType = type;
type = bindings[type];
//Ignores updating blocks that are the same and send block only to the player
if (b == (byte)((painting || action == 1) ? type : 0))
{
    if (painting || oldType != type) { SendBlockchange(x, y, z, b); } return;
}
Run Code Online (Sandbox Code Playgroud)

这是错误中突出显示的行:

if (b == (byte)((painting || action == 1) ? type : 0))

非常感谢帮助!

c# mono monodevelop

22
推荐指数
2
解决办法
1万
查看次数

将System.out重定向到JTextPane

我有一个类(如下所示)扩展JPanel并包含一个JTextPane.我想重定向System.outSystem.errJTextPane.我的班级似乎没有用.当我运行它时,它确实重定向系统打印,但它们不打印到我的JTextPane.请帮忙!

注意:仅在应用程序启动时重定向调用.但是在发布后的任何时候,System.out呼叫都不会被重定向到JTextPane.(即,如果我System.out.prinln();在类中放置一个,它将被调用,但是如果它被放置在以actionListener供以后使用,则它不会重定向).

public class OSXConsole extends JPanel {
    public static final long serialVersionUID = 21362469L;

    private JTextPane textPane;
    private PipedOutputStream pipeOut;
    private PipedInputStream pipeIn;


    public OSXConsole() {
        super(new BorderLayout());
        textPane = new JTextPane();
        this.add(textPane, BorderLayout.CENTER);

        redirectSystemStreams();

        textPane.setBackground(Color.GRAY);
        textPane.setBorder(new EmptyBorder(5, 5, 5, 5));

    }


    private void updateTextPane(final String text) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                Document doc = …
Run Code Online (Sandbox Code Playgroud)

java swing

11
推荐指数
2
解决办法
2万
查看次数

Java - 期待"""但发现了未知的令牌

我尝试从我的java应用程序执行applescript时收到此错误.代码如下:

String script = "tell application \"Terminal\" to do shell script \"/System/Library/CoreServices/Menu\\ Extras/user.menu/Contents/Resources/CGSession -suspend\" ";
ScriptEngineManager mgr = new ScriptEngineManager();
ScriptEngine engine = mgr.getEngineByName("AppleScript");
engine.eval(script);
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

Exception in thread "main" javax.script.ScriptException: Expected “"” but found unknown token.
    at apple.applescript.AppleScriptEngine.evalScript(Native Method)
    at apple.applescript.AppleScriptEngine.eval(AppleScriptEngine.java:342)
    at apple.applescript.AppleScriptEngine.eval(AppleScriptEngine.java:313)
    at myTestApp.Main.main(Main.java:25)
Run Code Online (Sandbox Code Playgroud)

谢谢你的考虑.

java applescript

6
推荐指数
2
解决办法
4837
查看次数

如何将脚本输出记录到 STDOUT 和文件

我有以下 Ruby 块:

ruby_block "Validate" do
  block do
    require "mixlib/shellout"
    begin
      cmd = Mixlib::ShellOut.new("/usr/local/bin/someScript.py", :timeout => 3600)
      cmd.live_stream = STDOUT
      cmd.run_command
      cmd.error!
    rescue Exception => e
      puts "Action failed..."
      return 168
    end
  end
  action :create
  notifies :create, "ruby_block[Validated]", :immediately
  not_if { node[:state][:validated] == true }
end
Run Code Online (Sandbox Code Playgroud)

我想将脚本的结果记录到 STDOUT 和一个名为“/tmp/xml_diff_results.txt”的文件中。

我做的第一件事是改变:

cmd=Mixlib::ShellOut.new("/usr/local/bin/someScript.py", :timeout => 3600)
Run Code Online (Sandbox Code Playgroud)

到:

cmd=Mixlib::ShellOut.new("/usr/local/bin/someScript.py > /tmp/xml_diff_results.txt", :timeout => 3600)
Run Code Online (Sandbox Code Playgroud)

然而,这并没有达到我的预期。

然后我注意到了这个cmd.live_stream变量。有没有办法我可以利用它并做这样的事情?:

cmd.live_stream = (STDOUT > /tmp/xml_diff_results.txt)
Run Code Online (Sandbox Code Playgroud)

解决方案:

我的问题的解决方案很简单,并受到@tensibai 的启发。

log_file = File.open('/tmp/chef-run.log', File::WRONLY | File::APPEND)
LOG …
Run Code Online (Sandbox Code Playgroud)

ruby mixlib-shellout

2
推荐指数
1
解决办法
1057
查看次数

从plist数组创建NSArray

我需要从plist数组中提取数据并将其放入NSArray中.但它似乎不起作用.

这是我的主要文件:

NSString *path = [[NSBundle mainBundle] pathForResource:@"htmlData" ofType:@"plist"];
NSMutableDictionary *tempDictionary = [[NSMutableDictionary alloc] initWithContentsOfFile:path];

dictionary = tempDictionary;
[tempDictionary release];

NSMutableArray *nameArray = [[NSMutableArray alloc] init];
nameArray = [dictionary objectForKey:@"tagName"];

self.sitesArray = nameArray;

[nameArray release];
Run Code Online (Sandbox Code Playgroud)

我的plist文件.命名:htmlData.plist

<plist version="1.0">
<dict>
    <key>tagName</key>
        <array>
            <string>&lt;html&gt;</string>
            <string>&lt;body&gt;</string>
        </array>
</dict>
</plist>
Run Code Online (Sandbox Code Playgroud)

它应该设置为self.sitesArray等于@"<html>", @"<body>, nil;但它不起作用.

iphone objective-c

0
推荐指数
1
解决办法
1467
查看次数

Java - ConcurrentModificationException

几乎每次调用时,下面的代码都会引发ConcurrentModificationException.第二段代码不会抛出异常,但它不是我需要的正确逻辑.如果对象是一个实例EditorFrame,我需要调用一个自定义处理策略,这就是close()方法.但是,如果它只是一个我希望它调用的基本帧dispose().

我环顾了这个网站并遵循了一些指示,但我找不到任何指示.

抛出异常的代码:

synchronized (frameList) {
    for (Iterator<JFrame> it = frameList.iterator(); it.hasNext();) {
        JFrame frame = it.next();
        if (frame instanceof EditorFrame) ((EditorFrame) frame).close();
        else frame.dispose();
        it.remove();
    }
}
Run Code Online (Sandbox Code Playgroud)

这段代码有效,但这不是我想要的:

synchronized (frameList) {
    for (Iterator<JFrame> it = frameList.iterator(); it.hasNext();) {
        JFrame frame = it.next();
        frame.dispose();
        it.remove();
    }
}
Run Code Online (Sandbox Code Playgroud)

谢谢你的帮助!

java concurrentmodification

-1
推荐指数
1
解决办法
642
查看次数