Error :This method must return a result of type UserBean
public UserBean isUserExist(String username)
{
UserBean objUserBean= new UserBean();
boolean found=false;
ArrayList users= (ArrayList)application.get("users");
if(users !=null)
{
Iterator it=users.iterator();
while(it.hasNext())
{
objUserBean=(UserBean)it.next();
if(objCommonBean.equals(objUserBean.getUsername()))
found=true;
break;
}
if(found)
return objUserBean;
}
else
return null;
}
}
Solution
One solution is
either avoid else and directly write return null ( i don't know why)
public UserBean isUserExist(String username)
{
UserBean objUserBean= new UserBean();
boolean found=false;
ArrayList users= (ArrayList)application.get("users");
if(users !=null)
{
Iterator it=users.iterator();
while(it.hasNext())
{
objUserBean=(UserBean)it.next();
if(objCommonBean.equals(objUserBean.getUsername()))
found=true;
break;
}
if(found)
return objUserBean;
}
return null;
}
}
Other Solution is :somewhat understandable
public UserBean isUserExist(String username)
{
UserBean objUserBean= new UserBean();
boolean found=false;
ArrayList users= (ArrayList)application.get("users");
if(users !=null)
{
Iterator it=users.iterator();
while(it.hasNext())
{
objUserBean=(UserBean)it.next();
if(objCommonBean.equals(objUserBean.getUsername()))
found=true;
break;
}
if(found)
return objUserBean;
}
else
return null;
return objUserBean;
}
}
{
UserBean objUserBean= new UserBean();
boolean found=false;
ArrayList users= (ArrayList)application.get("users");
if(users !=null)
{
Iterator it=users.iterator();
while(it.hasNext())
{
objUserBean=(UserBean)it.next();
if(objCommonBean.equals(objUserBean.getUsername()))
found=true;
break;
}
if(found)
return objUserBean;
}
return null;
}
}
Other Solution is :somewhat understandable
public UserBean isUserExist(String username)
{
UserBean objUserBean= new UserBean();
boolean found=false;
ArrayList users= (ArrayList)application.get("users");
if(users !=null)
{
Iterator it=users.iterator();
while(it.hasNext())
{
objUserBean=(UserBean)it.next();
if(objCommonBean.equals(objUserBean.getUsername()))
found=true;
break;
}
if(found)
return objUserBean;
}
else
return null;
return objUserBean;
}
}
No comments:
Post a Comment