Slash Slash - 1 year ago 72
Java Question

Why am I getting a 'class expected' error when placing a value into an array slot?

I'm new to this website so I barely a clue on how to use it, I tried, I'm sorry if I've made mistakes. My program intakes ten integer values and places them in an array, then displays the contents of the array in reverse. I keep receiving an error that states: class expected

Here's the code that it says is having the issue:

IntValues[number1] = int.parseInt (UserInput)

And here is the full code I've written:

class ReverseIntegers
public static void main (String[] args) throws IOException
String UserInput, Integers;
int number1 = 9;
int[] IntValues = new int[10];
InputStreamReader inStream = new InputStreamReader (;
BufferedReader num = new BufferedReader (inStream);
System.out.println ("Enter ten integer values and the program will display them in reverse order.");
while (number1 > -1)
UserInput = num.readLine();
IntValues[number1] = int.parseInt (UserInput);
System.out.println (number1 + " numbers are left to be entered, please continue.");
number1 = 0;
System.out.println ("The numbers entered in reverse order are: ");
while (number1 < 10)
System.out.println (IntValues[number1]);

Help! I don't know what the problem is!

Answer Source

Instead of int.parseInt(UserInput), you want Integer.parseInt(UserInput). The Integer class is the corresponding Object class for the primitive type int. This method that you are trying to access, parseInt(String value), is within that Integer class.

The error you are recieving makes sense, as int doesn't have any methods as it is a primitive type. It is telling you that you are trying to call a method from a primitive type, and that instead, a class is expected to be calling a method.