File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes int cannot be dereferenced Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "int cannot be dereferenced" Watch "int cannot be dereferenced" New topic
Author

int cannot be dereferenced

Nathalie cauchi
Greenhorn

Joined: Jan 14, 2010
Posts: 4
I am trying to implement a search method in my program but the error int cannot be dereferenced is continuously arising. What should i do?
the code is :



thanks

Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 2885
    
  13

Welcome to JavaRanch Nathalie,
When you post a source code, please UseCodeTags so that it makes easy to read your code.
I couldn't see any dereferencing error in your program as far as I've seen it. Which line is giving you that error?

Author of ExamLab ExamLab - a free SCJP / OCPJP exam simulator
My Home Page -- Twitter Profile -- JavaRanch FAQ -- How to Ask a Question
Nathalie cauchi
Greenhorn

Joined: Jan 14, 2010
Posts: 4
thanks

in lines 33,118, 140 and 162 :S
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36478
    
  16
You can only use a . after a variable name when that variable refers to an object (or a class, when you can call static members). If it is an int then you mustn't try putting . after it.

Never write == true or == false. Not only are they poor style, but also if you write = by mistake instead of == you can get some nasty errors later on.

Instead of if (xxx == true) . . . write if (xxx) . . . throughout.
Instead of if (xxx == false) . . . write if (!xxx) . . . throughout.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36478
    
  16
Since you are new (welcome to JavaRanch ) I shall add the code tags so you can see how much easier your post is to read.

Your search method looks long and unwieldy. You might do better to use the switch-case to call methods like searchByPrice or searchByDescription, which can be little neat methods. Variable names like param1 and param2 are confusing to read; they ought to have descriptive names if possible.
What is the number "j"? If you search through an array up to item "j", what happens if j ≥ myarray.length? Won't you suffer an Exception?
Nathalie cauchi
Greenhorn

Joined: Jan 14, 2010
Posts: 4

what should i therefore use instead of the . ?
Nathalie cauchi
Greenhorn

Joined: Jan 14, 2010
Posts: 4
thanks
I'm going to rewrite the method using smaller methods and see how it goes
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36478
    
  16
Nathalie cauchi wrote:
what should i therefore use instead of the . ?
If it is an int, you can't use anything. You can only write this sort of thing with ints.

I suspect you want the == operator. And of course an int cannot equal a String, so you will have to find methods to convert the String to an int. The first place to look for that is in the Integer class.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: int cannot be dereferenced
 
Similar Threads
JDBC Performance Win vs. AS/400
key with combinations
Diff between Java Stored Procedure and Oracle Stored Procedure
Pass Lots of Parameters to Methods
Calling Stored Procedure thru JPA