我一直在尋找解決這個問題的方法,無法找到任何我理解的東西。我正在做一個教程,並抄寫我老師輸入的所有東西,所以我只是在學習......但是當我這樣做時,它一直給我這個錯誤。由於我是新來這個,我不知道究竟發生了什麼意思或如何解決它:(不可編譯的源代碼:錯誤的Sym錯誤
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創造」的方法。我不知道如何解決它。我只是把什麼教程告訴我做。
這是PlayerNameConverter接口...
public interface PlayerNameConverter {
/**
* Convert the supplied name.
*
* @param name the name to convert.
*
* @return the converted name.
*/
String convertName(String name);
}
什麼是錯誤,精確?完全複製它。 –
我的賭注是轉換器和converterName的最終關鍵字。對不起,在手機上沒有IDE。 – stryba
你還有PlayerNameConverter接口嗎? – berry120