473,394 Members | 1,794 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

mismatch error

122 100+
Help please
I get this error at bottom of the program for (EmployeeClass idx : arlist)
I get the error on arlist
Type mismatch: cannot convert from element type Object to EmployeeClass


How do I solve this error.
Here is part of my code:

Expand|Select|Wrap|Line Numbers
  1. public class Employee_listing {
  2.     static ArrayList arlist;
  3.     static Scanner kbd;
  4.  
  5.     public static EmployeeClass makePerson() {
  6.         EmployeeClass temp = null;
  7.  
  8.         // prompt for data
  9.         String id;
  10.         String ln;
  11.         String fn;
  12.  
  13.         System.out.print("Enter Employee ID ==>");
  14.         id = kbd.next();
  15.  
  16.         System.out.print("Enter Last Name ==>");
  17.         ln = kbd.next();
  18.  
  19.         System.out.print("Enter First Name ==>");
  20.         fn = kbd.next();
  21.  
  22.  
  23.         // make an object
  24.         temp = new EmployeeClass(id,ln,fn);
  25.  
  26.         return temp;
  27.     }//close the public static EmployeeClass 
  28.  
  29.     public static void main(String[] args) {
  30.         // make array list object
  31.         arlist = new ArrayList();
  32.  
  33.         // make a scanner
  34.         kbd = new Scanner(System.in);
  35.  
  36.         // create people until select stop
  37.         boolean endData = false;
  38.  
  39.         while (!endData) {
  40.             EmployeeClass temp = makePerson();
  41.             arlist.add(temp);
  42.             System.out.println("More (Y/N)-->");
  43.  
  44.             String ans = kbd.next();
  45.  
  46.             if (ans.equalsIgnoreCase("N")) {
  47.                 endData = true;
  48.             }//close the if loop
  49.         }//close the while loop
  50.  
  51.         // print out all elements of array list
  52.         for (EmployeeClass idx : arlist) {
  53. System.out.printf("Name is %s - %s \n", idx.getFname(),idx.getLname());
  54. }
  55. }
Mar 21 '07 #1
2 1520
r035198x
13,262 8TB
Help please
I get this error at bottom of the program for (EmployeeClass idx : arlist)
I get the error on arlist
Type mismatch: cannot convert from element type Object to EmployeeClass


How do I solve this error.
Here is part of my code:

Expand|Select|Wrap|Line Numbers
  1. public class Employee_listing {
  2. static ArrayList arlist;
  3. static Scanner kbd;
  4.  
  5. public static EmployeeClass makePerson() {
  6.     EmployeeClass temp = null;
  7.  
  8. // prompt for data
  9.     String id;
  10.     String ln;
  11. String fn;
  12.  
  13. System.out.print("Enter Employee ID ==>");
  14. id = kbd.next();
  15.  
  16. System.out.print("Enter Last Name ==>");
  17. ln = kbd.next();
  18.  
  19. System.out.print("Enter First Name ==>");
  20. fn = kbd.next();
  21.  
  22.  
  23. // make an object
  24. temp = new EmployeeClass(id,ln,fn);
  25.  
  26. return temp;
  27. }//close the public static EmployeeClass 
  28.  
  29. public static void main(String[] args) {
  30. // make array list object
  31. arlist = new ArrayList();
  32.  
  33. // make a scanner
  34. kbd = new Scanner(System.in);
  35.  
  36. // create people until select stop
  37. boolean endData = false;
  38.  
  39. while (!endData) {
  40.     EmployeeClass temp = makePerson();
  41. arlist.add(temp);
  42. System.out.println("More (Y/N)-->");
  43.  
  44. String ans = kbd.next();
  45.  
  46. if (ans.equalsIgnoreCase("N")) {
  47. endData = true;
  48. }//close the if loop
  49. }//close the while loop
  50.  
  51. // print out all elements of array list
  52. for (EmployeeClass idx : arlist) {
  53. System.out.printf("Name is %s - %s \n", idx.getFname(),idx.getLname());
  54. }
  55. }
Define your ArrayList to take objects of type EmployeeClass.

Expand|Select|Wrap|Line Numbers
  1.  
  2. ArrayList<EmployeeClass > list = new ArrayList<EmployeeClass >(); 
  3.  
Mar 22 '07 #2
sandyw
122 100+
once again thanks for the help
Mar 22 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Stephen Briley | last post by:
For some reason, my posts are scrubbed as attachments. Lets hope that sending from the yahoo account works. I'm new to Python and I'm trying to do some database work with MS Access, but I can't...
2
by: Steve Briley | last post by:
I'm new to Python and I'm trying to do some database work with MS Access, but I can't seem to get around a "datatype mismatch error".&nbsp; Here's an example table that I'm working with... ...
5
by: Arun Wadhawan | last post by:
Hello MY SQL Server is causing me this problem : Microsoft VBScript runtime error '800a000d' Type mismatch: 'ident' >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> I am getting from...
1
by: LJgrnl | last post by:
I've got a type mismatch error that's driving me nutty. Variable blnNoData has the initial value False. If a recordset comes back empty (both .EOF and ..BOF are true) then blnNoData is set to...
4
by: Mike | last post by:
I am getting a type mismatch error when I do a bulk insert. ---Begin Error Msg--- Server: Msg 4864, Level 16, State 1, Line 1 Bulk insert data conversion error (type mismatch) for row 1, column...
1
by: Brett | last post by:
I have a form that calls a method within a DLL. By clicking a button on the form, the DLL is instantiated and the SaveOutlookMessage() method invoked. The DLL code copies messages from Outlook to...
6
by: Howard Kaikow | last post by:
I'm doing a VB 6 project in which I am trying to protect against type mismatch errors. Is the process any different in VB .NET? Here's what I'm doing in VB 6. I have an ActiveX DLL. The...
19
by: Steve | last post by:
ASP error number 13 - Type mismatch with SELECT...FOR UPDATE statement I got ASP error number 13 when I use the SELECT...FOR UPDATE statement as below. However, if I use SELECT statement without...
6
by: rn5a | last post by:
I am inserting records in a MS-Access database table. The data type of one of the columns named *OrderDate* in the DB table is Date/Time. This is the SQL query I am using to insert the records in...
1
by: nckinfutz | last post by:
hello, I am having a problem with an access database. this is not my database and I did not create it, nor am I very good at access. however, I am a network engineer and that is why this problem...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.