无法编译的源代码:错误的Sym错误

时间:2012-03-05 23:30:41

标签: java

我一直在寻找在互联网上解决这个问题的方法,并且找不到任何我理解的东西。我正在做一个教程并复制出我老师输入的所有内容,所以我只是在学习..但是当我这样做时,它一直给我这个错误。由于我是新手,我不知道它意味着什么或如何解决它:(

public final class DefaultPlayerNameConverter
        implements PlayerNameConverter
{

    /**
     * Must be created through the create method.
     */
    private DefaultPlayerNameConverter()
    {
    }

    /**
     * Create a DefaultPlayerNameConverter.
     * 
     * @return a DefaultPlayerNameCOnverter.
     */
    public static DefaultPlayerNameConverter create()
    {
        final DefaultPlayerNameConverter converter;

        converter = new DefaultPlayerNameConverter();

        return (converter);
    }

    /**
     * Convert player name to remove leading/trailing whitespace.
     * 
     * @param name the name to convert.
     * 
     * @return the converted name.
     * 
     * @throws IllegalArgumentException if name is null.
     */
    @Override
    public String convertName(final String name)
    {
        final String convertedName;

        if(name == null)
        {
            throw new IllegalArgumentException("name cannot be null");
        }

        convertedName = name.trim();

        return (convertedName);
    }
}

public class DefaultPlayerNameConverterTest {

    public DefaultPlayerNameConverterTest() {
    }

    /**
     * Test bad arguments to the convertName method.
     */
    @Test
    public void testConvertBadName() 
    {
        try
        {
            new DefaultPlayerNameConverter.create().convertName(null);
            fail("convertName(null) must throw an "
                    + "IllegalArgumentException");
        }
        catch(final IllegalArgumentException ex)
        {
            assertEquals("name cannot be null", ex.getMessage());
        }
    }

        /**
         * Test good arguments to the convertName method.
         */
        @Test
        public void testConvertGoodName()
        {
            checkConvertName("", "");
            checkConvertName("\t", "");
            checkConvertName("\n", "");
            checkConvertName("\r", "");
            checkConvertName("\r\n", "");
            checkConvertName("\r\n\t", "");
            checkConvertName("X", "X");
            checkConvertName(" X", "X");
            checkConvertName("X ", "X");
            checkConvertName(" X ", "X");
            checkConvertName("X Y", "X Y");
            checkConvertName("Hello\tworld", "Hello\tworld");
        }
        /**
         * Check that the name conversion works.
         * 
         * @param originalName the name to convert.
         * @param expectedName what the name should be converted to.
         */
        private void checkConvertName(final String originalName, 
                                      final String expectedName)
        {
            final PlayerNameConverter converter;
            final String convertedName;

            converter = new DefaultPlayerNameConverter.create();
            convertedName = converter.convertName(originalName);
            assertEquals(expectedName, convertedName);

        }
}

当我添加“DefaultPlayerNameConverter create”方法时,错误会一直显示在我的测试类中。我不知道如何解决它。我只是把教程告诉我的内容。


这是PlayerNameConverter界面......

public interface PlayerNameConverter {

    /**
     * Convert the supplied name.
     * 
     * @param name the name to convert.
     * 
     * @return the converted name.
     */
    String convertName(String name);
}

1 个答案:

答案 0 :(得分:1)

这一行:

new DefaultPlayerNameConverter.create().convertName(null);

不应该有new关键字,它应该只是

DefaultPlayerNameConverter.create().convertName(null);