This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

long can not be deferenced

 
Roberto Favaro
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone help me avoid my error.Long cannot be deferenced. OrderId must be of type long

 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure that is the code that is causing the error? What you've posted won't compile, but for a different reason than your error.
 
Roberto Favaro
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a huge dao which is talking to a database.I want to check if the id exists but the .length() method is the problem as the id (type long) cannot be deferenced
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Two problems:
  • long is a primitive type.
  • The type Long does not have a length() method.

  •  
    Roberto Favaro
    Greenhorn
    Posts: 24
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thank you.Is there another way to write this without having to change the type
     
    Paul Sturrock
    Bartender
    Posts: 10336
    Eclipse IDE Hibernate Java
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I dunno, its hard to understand what you are trying to do. What it looks like you might be trying to do is see if a value has been assigned to orderId and if it has been return 0. Is that right?
     
    Roberto Favaro
    Greenhorn
    Posts: 24
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Yes......I changed my code to use a primaryKey generator to generate a unique Id and removed the need for a check.Thank you for ure help
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic