A
AC Question
Here is my code in this code i am trying to register the user by getting the basic details like firstname,lastname,email,password and put those details in my database on res.partner table. It works perfectly and as i have mentioned in my code i am getting an unique customer id whenever i click register button. Then i have an another method called registeruser wherein i am storing the emailid,password and the customerid that have been generated in the register method and storing those details in res.users table. here my problem is i am getting the class cast exception inside the register user method help me out please.
Here is my code:
public Integer register(String Firstname,String Lastname,String Email,String Password){
//log.debug("In Register...");
XmlRpcClient client = getXmlRpcClient();
try {
HashMap<String, Object> fields = new HashMap<String, Object>();
fields.put("name",Firstname );
fields.put("display_name", Lastname);
fields.put("email", Email);
fields.put("password", Password);
//log.debug("Got the customer fields, rpc call to create customer");
List<Object> callParams = getCallParameters("res.partner", MainActivity.ActionType.CREATE);
callParams.add(fields);
// Toast.makeText(getApplicationContext(), "4", Toast.LENGTH_LONG).show();
Object result = client.execute("execute", callParams);
//Toast.makeText(getApplicationContext(), "5", Toast.LENGTH_LONG).show();
Integer customerId = (result != null) ? (Integer) result : null;
Toast.makeText(getApplicationContext(),"Customer/Partner record created, Id = " +customerId, Toast.LENGTH_LONG).show();
//log.debug("Customer/Partner record created, Id = " + customerId);
//log.debug("About to create a user login in res_users");
registerUser(Email, Password,customerId);
return customerId;
} catch (Exception e) {
Toast.makeText(getApplicationContext(), "7"+e, Toast.LENGTH_LONG).show();
System.out.println("Excpt" + e);
Log.d(null, Log.getStackTraceString(new Exception()));
e.printStackTrace();
//throw e;
//log.error(e.getMessage());
//log.error(e.fillInStackTrace());
}
return 0;
}
private String registerUser(String Email, String Password, Integer customerId) {
XmlRpcClient client = getXmlRpcClient();
Toast.makeText(getApplicationContext(), "reguser method", Toast.LENGTH_LONG).show();
try {
Toast.makeText(getApplicationContext(), "try block", Toast.LENGTH_LONG).show();
HashMap<String, Object> fields = new HashMap<String, Object>();
fields.put("login", Email);
fields.put("password", Password);
fields.put("partner_id", customerId);
Toast.makeText(getApplicationContext(), "crsd put field", Toast.LENGTH_LONG).show();
List<Object> callParams = getCallParameters("res.users", MainActivity.ActionType.CREATE);
callParams.add(fields);
Toast.makeText(getApplicationContext(), "Finished res.users", Toast.LENGTH_LONG).show();
Object result = client.execute("execute", callParams);
Toast.makeText(getApplicationContext(), "Client execut done", Toast.LENGTH_LONG).show();
Integer userId = (result != null) ? (Integer) result : null;
Toast.makeText(getApplicationContext(),"New user id = " +userId, Toast.LENGTH_LONG).show();
// log.debug("New user id = " + userId);
return userId.toString();
} catch (Exception e) {
Toast.makeText(getApplicationContext(), "7"+e, Toast.LENGTH_LONG).show();
System.out.println("Excpt" + e);
Log.d(null, Log.getStackTraceString(new Exception()));
e.printStackTrace();
//log.error(e.getMessage());
//log.error(e.fillInStackTrace());
// e.printStackTrace();
}
return "";
}
Here is my code:
public Integer register(String Firstname,String Lastname,String Email,String Password){
//log.debug("In Register...");
XmlRpcClient client = getXmlRpcClient();
try {
HashMap<String, Object> fields = new HashMap<String, Object>();
fields.put("name",Firstname );
fields.put("display_name", Lastname);
fields.put("email", Email);
fields.put("password", Password);
//log.debug("Got the customer fields, rpc call to create customer");
List<Object> callParams = getCallParameters("res.partner", MainActivity.ActionType.CREATE);
callParams.add(fields);
// Toast.makeText(getApplicationContext(), "4", Toast.LENGTH_LONG).show();
Object result = client.execute("execute", callParams);
//Toast.makeText(getApplicationContext(), "5", Toast.LENGTH_LONG).show();
Integer customerId = (result != null) ? (Integer) result : null;
Toast.makeText(getApplicationContext(),"Customer/Partner record created, Id = " +customerId, Toast.LENGTH_LONG).show();
//log.debug("Customer/Partner record created, Id = " + customerId);
//log.debug("About to create a user login in res_users");
registerUser(Email, Password,customerId);
return customerId;
} catch (Exception e) {
Toast.makeText(getApplicationContext(), "7"+e, Toast.LENGTH_LONG).show();
System.out.println("Excpt" + e);
Log.d(null, Log.getStackTraceString(new Exception()));
e.printStackTrace();
//throw e;
//log.error(e.getMessage());
//log.error(e.fillInStackTrace());
}
return 0;
}
private String registerUser(String Email, String Password, Integer customerId) {
XmlRpcClient client = getXmlRpcClient();
Toast.makeText(getApplicationContext(), "reguser method", Toast.LENGTH_LONG).show();
try {
Toast.makeText(getApplicationContext(), "try block", Toast.LENGTH_LONG).show();
HashMap<String, Object> fields = new HashMap<String, Object>();
fields.put("login", Email);
fields.put("password", Password);
fields.put("partner_id", customerId);
Toast.makeText(getApplicationContext(), "crsd put field", Toast.LENGTH_LONG).show();
List<Object> callParams = getCallParameters("res.users", MainActivity.ActionType.CREATE);
callParams.add(fields);
Toast.makeText(getApplicationContext(), "Finished res.users", Toast.LENGTH_LONG).show();
Object result = client.execute("execute", callParams);
Toast.makeText(getApplicationContext(), "Client execut done", Toast.LENGTH_LONG).show();
Integer userId = (result != null) ? (Integer) result : null;
Toast.makeText(getApplicationContext(),"New user id = " +userId, Toast.LENGTH_LONG).show();
// log.debug("New user id = " + userId);
return userId.toString();
} catch (Exception e) {
Toast.makeText(getApplicationContext(), "7"+e, Toast.LENGTH_LONG).show();
System.out.println("Excpt" + e);
Log.d(null, Log.getStackTraceString(new Exception()));
e.printStackTrace();
//log.error(e.getMessage());
//log.error(e.fillInStackTrace());
// e.printStackTrace();
}
return "";
}