gpt4 book ai didi

java - 无法编译的源代码 : Erroneous Sym Error

转载 作者:行者123 更新时间:2023-12-01 15:30:31 24 4
gpt4 key购买 nike

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

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 接口(interface)...

public interface PlayerNameConverter {

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

最佳答案

这一行:

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

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

DefaultPlayerNameConverter.create().convertName(null);

关于java - 无法编译的源代码 : Erroneous Sym Error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9575718/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com