Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
107 views
in Technique[技术] by (71.8m points)

java - Error of int cannot be dereferenced?

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<intArray.length; ++i)
    {
    Array[i] = intArray[i].toString();
    }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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])


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...