如何阻止Java / Eclipse将stdout和stderr放在一起?

时间:2015-03-17 17:45:14

标签: java eclipse stdout stderr

所以这就是我参与的计划中的输出:

java.lang.IllegalArgumentException: argument type mismatch
CreationDate
getCreationDate
setCreationDate
LastModifiedDate
getLastModifiedDate
setLastModifiedDate
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at Transform.transform(Transform.java:86)
    at Experiment.main(Experiment.java:120)
java.lang.IllegalArgumentException: argument type mismatch
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at Transform.transform(Transform.java:86)
    at Experiment.main(Experiment.java:120)
DeletionDate
getDeletionDate
setDeletionDate

调用它的代码:

    for (Field f : databaseFields) {
        String upperCamelCase = Character.toUpperCase(f.getName().charAt(0)) + f.getName().substring(1);
        System.out.println(upperCamelCase);

        String getMethodName = "get" + upperCamelCase;
        System.out.println(getMethodName);

        Method getMethod = null;
        try {
            getMethod = databaseClass.getDeclaredMethod(getMethodName);
        } catch (NoSuchMethodException e) { 
        } catch (SecurityException e) { }

        if (getMethod == null) {
            getMethodName = "is" + upperCamelCase;
            try {
                getMethod = databaseClass.getDeclaredMethod(getMethodName);
            } catch (NoSuchMethodException e) {
                continue;
            } catch (SecurityException e) {
                continue;
            }
        }

        String setMethodName = "set" + upperCamelCase;
        System.out.println(setMethodName);
        Method setMethod = null;
        for (int i = 0; i < parameterTypes.length; i++) {
            try {
                setMethod = jsonClass.getDeclaredMethod(setMethodName, parameterTypes[i]);
            } catch (NoSuchMethodException e) { }
        }

        if (setMethod == null) {
            continue;
        }

        try {
            setMethod.invoke(jsonObject, getMethod.invoke(databaseObject));
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
    }

这是一个反射变换,显然我不能告诉它引发异常的get或set方法。我该如何解决这个问题?

2 个答案:

答案 0 :(得分:3)

在Eclipse中,Console中的stderr和stdout的颜色不同。您还可以通过右键单击控制台窗口并选择“首选项”来隐藏其中一个。

在命令行中,您可以使用重定向>2>将stderr或stdout发送到单独的文件。

答案 1 :(得分:2)

呼叫

System.out.flush();
每次println调用后

立即强制输出​​到控制台。