• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Arrays

 
Naveen R R
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could anyone please tell me how to correct the following error?
Type mismatch: cannot convert from java.lang.String to security.DeptRoleBean
Code:
public class DeptRoleBean {
private java.lang.String roleId;
----
----
----getter/setter methods----
}
public class OfficeUserBean {
private DeptRoleBean[] deptRole;
-----
----getter/setter methods----
}
public class SecurityTest extends HttpServlet {
private Connection connection = null;
-----
public void performTask(HttpServletRequest req, HttpServletResponse res) {
try {
String roleId = req.getParameter("txtRole_Id");
---------
---------
OfficeUserBean user = new OfficeUserBean();
DeptRoleBean[] deptRole = new DeptRoleBean[5];
deptRole[0] = roleId; //Error
-----
user.setDeptRole(deptRole);
Thanks,
Naveen
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13071
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"
Could anyone please tell me how to correct the following error?
Type mismatch: cannot convert from java.lang.String to security.DeptRoleBean
"
The error message is telling you exactly what is wrong. You are trying to put a String into an array of DeptRoleBean reference.
 
k b
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
DeptRoleBean[] deptRole = new DeptRoleBean[5];
deptRole[0] = roleId; //Error
This may Help:--
DeptRole tmp = new DeptRole();
tmp.setRoleId(roleID);
deptRole[0] = tmp;
 
k b
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
DeptRoleBean[] deptRole = new DeptRoleBean[5];
deptRole[0] = roleId; //Error
This may Help:--
DeptRole tmp = new DeptRole();
tmp.setRoleId(roleID);
deptRole[0] = tmp;
 
Naveen R R
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, k b. It works now.
Naveen
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic