我想知道是否有一种方法可以将整数数组转换为java中的一组字符。我不断收到一个nullPointer异常错误。在Java中铸造
这是我...
private char [] clubsArray; // Will hold the clubsString String as an array
private char [] heartsArray;// Will hold the heartsString String as an array
private char [] spadesArray;// Will hold the spadesString String as an array
private char [] diamondsArray;// Will hold the diamondsString String as an array
private int [] intClubsArray; // Holds the character array as number values so I can sort it properly
private int [] intHeartsArray; // Holds the character array as number values so I can sort it properly
private int [] intSpadesArray; // Holds the character array as number values so I can sort it properly
private int [] intDiamondsArray; // Holds the character array as number values so I can sort it properly
public void cast()
{
for (int i = 0; i < clubsArray.length; i++)// A loop that will cast all the clubs into ints
{
intClubsArray[i] = (int) clubsArray[i];
}
for (int i = 0; i < heartsArray.length; i++)// A loop that will cast all the hearts into ints
{
intHeartsArray[i] = (int) heartsArray[i];
}
for (int i = 0; i < spadesArray.length; i++)// A loop that will cast all the spades into ints
{
intSpadesArray[i] = (int) spadesArray[i];
}
for (int i = 0; i < diamondsArray.length; i++)// A loop that will cast all the diamonds into ints
{
intDiamondsArray[i] = (int) diamondsArray[i];
}
}
为什么会出现这个错误?它可以固定?我可以投出整个阵列吗?此外我不想为变量设置一个特定的大小,因为当它变成一个int []时,我将获得不必要的0作为空格。
你应该初始化正确的尺寸和类型的INT数组。 – Senthil 2011-04-04 00:22:21