Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Retriving data from vector by matching user id

 
sahana mithra
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
sahana mithra
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The stack trace should tell you exactly where the error happens. Can you post it here ?
 
sahana mithra
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[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
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
does it compile without errors now ?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic