小编mas*_*nik的帖子

打印异常与Exception.getMessage

是否有使用以下两个关于异常的代码的最佳实践.

//code1

} catch (SomeException e) {
    logger.error("Noinstance available!", e.getMessage());
}

//code2
} catch (SomeException e) {
    logger.error("Noinstance available!", e);
}
Run Code Online (Sandbox Code Playgroud)

我什么时候应该使用异常的getMessage方法?

java exception

25
推荐指数
1
解决办法
4万
查看次数

Ansible命令模块不能执行参数

这里有一个Ansible noobie.

我遇到的问题是当我使用"命令"模块执行命令时,它将失败.在远程主机和localhost上也尝试过这个.

基础信息:

版本:ansible 2.0.0(开发2c9d1257ba)

核心:(分离的HEAD 5983d64d77)上次更新时间2015/05/30 07:22:33(GMT +800)

其他:(分离头HEAD 1276420a3a)最后更新时间2015/05/30 07:22:41(GMT +800)

Ansible主机文件

local   ansible_ssh_host=127.0.0.1  ansible_ssh_port=22 ansible_ssh_user=root ansible_ssh_pass=a
Run Code Online (Sandbox Code Playgroud)

命令

ansible -i ansible_hosts -m command -a "/usr/bin/ls" local
Run Code Online (Sandbox Code Playgroud)

实际结果

local | FAILED! => {u'msg': u'Traceback (most recent call last):\r\n 
File
"/root/.ansible/tmp/ansible-tmp-1436165888.5-23845581569171/command",
line 2139, in <module>\r\n    main()\r\n  File
"/root/.ansible/tmp/ansible-tmp-1436165888.5-23845581569171/command",
line 158, in main\r\n    module =
CommandModule(argument_spec=dict())\r\n  File
"/root/.ansible/tmp/ansible-tmp-1436165888.5-23845581569171/command",
line 606, in __init__\r\n    self._check_for_check_mode()\r\n  File
"/root/.ansible/tmp/ansible-tmp-1436165888.5-23845581569171/command",
line 1142, in _check_for_check_mode\r\n    for (k,v) in
self.params.iteritems():\r\nAttributeError: \'tuple\' object has no
attribute \'iteritems\'\r\n', u'failed': …
Run Code Online (Sandbox Code Playgroud)

ansible

14
推荐指数
1
解决办法
884
查看次数

使用 java 在 github 上创建问题

我想使用 java EGIT API 在 GitHub 上创建问题。

我试过了:

GitHubClient client = new GitHubClient().setCredentials("abc", "xyz");

IssueService service = new IssueService(client);

Repository repo = new Repository();
Run Code Online (Sandbox Code Playgroud)

java github issue-tracking egit

5
推荐指数
1
解决办法
142
查看次数

JavaFx,@ FXML的问题

我是java的新手,所以我得请你帮忙:P.我正在创建非常简单的程序,但我坚持验证密码和登录textField.我想知道那段代码有什么问题,你能帮帮我吗?

调节器

package sample;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.PasswordField;

import java.awt.*;

public class Controller {
    @FXML
    public TextField login,password;
    public void LoginButtonClicked(ActionEvent event)
    {
    if(login.getText().equals("yes")&&password.getText().equals("yes"))
        {
            System.out.print("Congratulations");
        }
    else
        {
            System.out.print("no");
        }

    }


}
Run Code Online (Sandbox Code Playgroud)

FXML

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.text.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>

<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.Controller">
   <top>
      <VBox BorderPane.alignment="CENTER">
         <children>
            <MenuBar>
              <menus>
                <Menu mnemonicParsing="false" text="Profile">
                  <items>
                    <MenuItem …
Run Code Online (Sandbox Code Playgroud)

javafx fxml

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

jtree无法获取特定节点的索引

我有jTree(例如):

-paper
    -coated
    -glossy
        -hummermill
        -quatro
        -springhill
    -matte
Run Code Online (Sandbox Code Playgroud)

当我选择springhill我得到5的索引,但我不想从根(纸)(包括父母和光泽外的其他节点)计数,我想从hummermill开始计数所以我试图获得2的索引.

我使用tree.getLeadSelectionRow()并获得5的int值; 我也使用node.getIndex(node)但在这里我没有得到任何正常的(0,3,-1).我尝试了节点和树的所有方法的所有变化,并找不到任何有用的东西.请求帮助!

java swing jtree

3
推荐指数
1
解决办法
1475
查看次数

wordpress在wordpress循环中获取自定义帖子类型的类别名称?

我想在查询帖子循环中获取自定义帖子类型的类别名称.

这是我的代码:

query_posts(array('post_type'=>'portfolio','posts_per_page'=>4, 'orderby' => 'ID', 'order' => 'DESC' ));

while ( have_posts() ) : the_post();

<li>
    <div class="foli_img"> <a href="<?php echo get_permalink();?>"> <span class="next"> </span> </a> <?php the_post_thumbnail();?> </div>
    <h3 class="style"><?php the_title();?></h3>
    <?php the_content();?>
    <h4><a  href="#">I want the category name here</a></h4>
</li>
<?php endwhile;?>
Run Code Online (Sandbox Code Playgroud)

php wordpress

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

在click react.js上切换列表的背景颜色

我正在尝试创建一个具有以下功能的列表.

  1. 在悬停时更改listItem的背景颜色.
  2. 单击更改listItem的背景颜色.
  3. 在点击的元素之间切换背景颜色.[即列表中只有一个元素可以点击属性]

我已经执行了onhover 1和2功能,但我无法实现第3个功能.请帮我解决这个问题.

提前致谢.

/** @jsx React.DOM */

   'use strict'

    var React = require('react')


    var ListItem = React.createClass({

        getInitialState: function() {
            return  {hover_flag: false, click_flag: false}
        },

        hoverEvent: function() {
            this.setState({hover_flag: !this.state.hover_flag})
        },

        clickEvent: function(){
            this.setState({click_flag: true})
        },

        render: function() {
            var liStyle = {
                /* some more class properties */
                background: '#cc181e',
            }

            if(this.state.hover_flag || this.state.click_flag) {
                liStyle['background'] = '#880000'
            }

            if(this.state.click_flag) {
                liStyle['background'] = '#880000'           
            }

            return (
                <li onClick={this.clickEvent} onMouseEnter={this.hoverEvent} onMouseLeave={this.hoverEvent} style={liStyle} key={this.props.name}>{this.props.name}</li>
            ) …
Run Code Online (Sandbox Code Playgroud)

javascript jquery reactjs

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

给定代码的时间复杂度是多少?

import java.util.Scanner;


public class PairsOfElementsSumEqualsN {

    public static void main(String[] args) {
        // TODO Auto-generated method stub

        Scanner s  = new Scanner(System.in);

        System.out.println("enter the number");

        int n = s.nextInt();

        int[] array = new int[]{1,2,1,2,4,5,6,7,8,9};

        int j = 0;
        int i = 0;

        for(i = 0 ; i<array.length;i++)
        {
            for(j=i+1;j<array.length;j++)
            {
                if(array[i] + array[j] == n)
                {
                    System.out.println(array[i] + "," + array[j]);
                }

            }
        }

    }

}
Run Code Online (Sandbox Code Playgroud)

我认为它应该是n ^ 2但我想要答案的解释

java time-complexity

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