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 Retriving data from vector by matching user id 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 "Retriving data from vector by matching user id " Watch "Retriving data from vector by matching user id " New topic
Author

Retriving data from vector by matching user id

sahana mithra
Ranch Hand

Joined: Oct 26, 2010
Posts: 72
how to create an employee class with employee id's,name and address,how can we store in vector, and how we can display his name and address from the vector when an employee id is given.
Below is my code which i have tried.



Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

And ? What is your problem ?

I can spot one at line 13. You are not comparing Strings the way they should be compared. Use the equals() method instead.


[My Blog]
All roads lead to JavaRanch
sahana mithra
Ranch Hand

Joined: Oct 26, 2010
Posts: 72
Hi christophe,
My problem is i have a return null statement. I compare and return emp1. But i receive that null only. How should I change the method so as to return emp1?
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

The stack trace should tell you exactly where the error happens. Can you post it here ?
sahana mithra
Ranch Hand

Joined: Oct 26, 2010
Posts: 72
[img]C:\Program Files\Java\jdk1.6.0_14\bin>javac EmployeeSearch.java
EmployeeSearch.java:12: cannot find symbol
symbol : class EmployeeToCache
location: class EmployeeSearch
EmployeeToCache emp_cache=new EmployeeToCache();
^
EmployeeSearch.java:12: cannot find symbol
symbol : class EmployeeToCache
location: class EmployeeSearch
EmployeeToCache emp_cache=new EmployeeToCache();
^
EmployeeSearch.java:21: cannot find symbol
symbol : method getId()
location: class Employee
if(emp_id==emp1.getId()) {
^
3 errors[/img]
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

AvoidRedHerrings. You were talking about a null statement, and all you have is "cannot find symbol".

EmployeeToCache is not found. Is it in its own file ? Is it compiled ? Is it in your classpath ?
sahana mithra
Ranch Hand

Joined: Oct 26, 2010
Posts: 72
Hi Christophe
It is really not intentional. The code I have posted worked fine. The problem was with return statement. After putting try catch it shown the errors I posted. I am a very beginner so I was not able to analyze that good as how you did. Thanks for your replies I l set the correct classpath as you have suggested.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

does it compile without errors now ?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Retriving data from vector by matching user id
 
Similar Threads
Comparable and Comparator
Clarifications/Suggestions in Java
Problem with refresh() method of EntityManamger in JPA
what is the error in this program
Basic hibernate code explanation