| Author |
int cannot be derefrenced
|
theodore sklavenitis
Greenhorn
Joined: Dec 16, 2010
Posts: 4
|
|
I get an error telling me that int cannot be derefrenced.I a, a begginer and i really cant see what i am doing wrong
|
 |
Christophe Verré
Sheriff
Joined: Nov 24, 2005
Posts: 14672
|
|
Welcome to the ranch !
You probably wanted to loop through the array, so n.length should be numArray.length, or simply use n.
Next time, please UseCodeTags, and tell us exactly where the error happens (line number and exact error message).
|
[My Blog]
All roads lead to JavaRanch
|
 |
Alex Hurtt
Ranch Hand
Joined: Oct 26, 2010
Posts: 98
|
|
Ok, first of all you have this a couple of times:
for (int i = 0; i <n.length;i++)
when what you probably mean is this:
for (int i = 0; i < numArray.length; i++)
Your variable n is just an integer primitive...it has no length property.
As a small matter of coding practice consider changing the following:
to just
No need to declare the local variable without initializing it to some value here.
I'm not sure what is giving you an error saying 'cannot be dereferenced' but for me when I popped your code into Eclipse it instantly pointed out to me that
"The primitive type int of n does not have a field length"
|
 |
Christophe Verré
Sheriff
Joined: Nov 24, 2005
Posts: 14672
|
|
Alex Hurtt wrote:
I'm not sure what is giving you an error saying 'cannot be dereferenced' but for me when I popped your code into Eclipse it instantly pointed out to me that
"The primitive type int of n does not have a field length"
Try to compile from the command line.
|
 |
Alex Hurtt
Ranch Hand
Joined: Oct 26, 2010
Posts: 98
|
|
Christophe Verré wrote:
Alex Hurtt wrote:
I'm not sure what is giving you an error saying 'cannot be dereferenced' but for me when I popped your code into Eclipse it instantly pointed out to me that
"The primitive type int of n does not have a field length"
Try to compile from the command line.
Ok I did and I got the authors error with the code as it was written...rather wierd way for the compiler to tell me that a primitive int doesn't have a .length property. When I make the modifications I suggested to the code, it compiles fine.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32708
|
|
|
Writing error messages which users can understand is the most difficult part of creating a compiler. Eclipse is much better for error messages than the Sun/Oracle compiler.
|
 |
 |
|
|
subject: int cannot be derefrenced
|
|
|