Type missmatch, cant convert from int to object.

J

Juggernaut

I cant this to work.

I have already created the objects and such, now I want to fill it up with
random numbers. But I get that a type missmatch where it cant convert from
int to object. Neither can it work with the math.random class, same error
there.

Here is what Im trying to do:

// Fills array with random numbers,
for (int row=0; row < myCalendar.length; row++)
{
for (int col=0; col < myCalendar[row].length; col++){
{
num1 = generator.nextInt(100);
myCalendar[row][col] = num1;}
}
}
 
R

Ryan Stewart

Juggernaut said:
I cant this to work.

I have already created the objects and such, now I want to fill it up with
random numbers. But I get that a type missmatch where it cant convert from
int to object. Neither can it work with the math.random class, same error
there.

Here is what Im trying to do:

// Fills array with random numbers,
for (int row=0; row < myCalendar.length; row++)
{
for (int col=0; col < myCalendar[row].length; col++){
{
num1 = generator.nextInt(100);
myCalendar[row][col] = num1;}
}
}
You haven't posted enough code for anyone to tell you for sure what your
problem is. I'll take a couple guesses though. I'd guess from your
description of the error that you have an object array and you're trying to
put ints in it. That won't work because an int isn't an object. As for your
"math.random" class, that's not a class. There's a method: Math.random() and
a class named java.util.Random. In the future, post executable code that
demonstrates your problem along with the exception you're getting. See
http://www.physci.org/codes/sscce.jsp for tips.
 
B

Bobo

I'm assuming myCalendar is a two-dimensional array of Integer, or Object?

Either create an array of int, or encapsulate the int in an Integer object,
ie.

int i = 3;
Integer integer = new Integer(i);

An "int" is a primitive type, not an object, so if you need an object (to
put in a List, or whatever), you've got to package it up in an Integer.

Paul
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top