• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

int cannot be derefrenced

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).
 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Marshal
Posts: 80634
471
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic