Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can anyone tell we whats the issue while calling the method em new to android....it is showing error "the method getName(); is undefined for the type arraylist<employee>?

public ArrayList<Employee> getEmployee(){
		ArrayList<Employee> emplist = new ArrayList<Employee>();
		try {
			open();
			Cursor cursor = db.rawQuery("select * from tbl_employee", null);
			  Boolean bRunning = cursor.moveToFirst();
				while (bRunning)
				{
					Employee emp = new Employee();
					emp.setName(cursor.getString(cursor.getColumnIndex("fld_employeename")));
					emp.setdesignation(cursor.getString(cursor.getColumnIndex("fld_designation")));
					emp.setempno(cursor.getInt(cursor.getColumnIndex("fld_employeeno")));
				    Log.d("Log_Name", emp.getName());
				    Log.d("Log_Password", emp.getdesignation());
				    Log.d("Log_Status", String.valueOf(emp.getempno()));
				    bRunning = cursor.moveToNext();
				    emplist.add(emp);
				} 
		     	cursor.close();
		    	db.close();	
		}
        catch (NullPointerException ex) 
		{
        	Log.v("get_User_query", "successful");
			ex.printStackTrace();		
		}
		return emplist;
	}


This is how em calling this method
ArrayList<employee> emplist= dbhelper.getEmployee();
String name = emplist.getName();
String designation = emplist.getdesignation();

What I have tried:

i dont know what to try for this
Posted
Updated 9-Sep-16 10:16am
Comments
Richard Deeming 8-Sep-16 14:51pm    
The error message is quite clear - emplist is an ArrayList<Employee>, which doesn't contain a method called getName.

What are you expecting the name variable to contain?

See ArrayList (Java Platform SE 7 )[^] where it shows all the methods available for that class.
 
Share this answer
 
You are trying to call the *employee* getname method, but you're dealing with a *collection* of employees. You need to say which employee's name you want something like ...

string empName = empList.get ( 1 ).getName ();

would get you the *second* entry in the list.

It might be a good idea to rename your db retrieval method to getEmployees to make it clear you're dealing with more than one item.
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900