I am getting an error with this constructor, and i have no idea how to fix? I am a beginner at java. This is from an example exercise that i was trying to learn:
/**
* Create an array of size n and store a copy of the contents of the
* input argument
* @param intArray array of elements to copy
*/
public IntArray11(int[] intArray)
{
int i = 0;
String [] Array = new String[intArray.length];
for(i=0; i
{
Array[i] = intArray[i].toString();
}
}
解决方案
int is not an object in java (it's a primitive), so you cannot invoke methods on it.
One simple way to solve it is using
Integer.toString(intArray[i])