When I deploy my application in my android device and try to click the register button, it throws a java null pointer exception in the lines:
register(Fname,Lname,Email,Password)
and
Object result = client.execute("execute", callParams);
My Mainactivity code and a stack trace are shown below.
Please help me resolve these errors.
public class MainActivity2 extends Activity {
public void onCreate(Bundle savedInstanceState ){
super.onCreate(savedInstanceState);
setContentView(R.layout.next);
EditText ed1;
ed1=(EditText) findViewById(R.id.editText);
final String Fname=ed1.getText().toString();
EditText ed2;
ed2=(EditText)findViewById(R.id.editText2);
final String Lname=ed2.getText().toString();
EditText ed3;
ed3=(EditText)findViewById(R.id.editText3);
final String Email=ed3.getText().toString();
EditText ed4;
ed4=(EditText)findViewById(R.id.editText4);
final String Password=ed4.getText().toString();
Button btn3;
btn3=(Button) findViewById(R.id.button3);
btn3.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
try {
register(Fname, Lname, Email, Password);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
public Integer register(String Firstname,String Lastname,String Email,String Password)throws Exception{
//log.debug("In Register...");
Toast.makeText(getApplicationContext(), "1", Toast.LENGTH_LONG).show();
XmlRpcClient client = getXmlRpcClient();
try {
System.out.println(getXmlRpcClient());
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);
Toast.makeText(getApplicationContext(), "3", Toast.LENGTH_LONG).show();
//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(), "+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());e
}
//return 0;
}
Stack trace:
Even i entered the value in my edit text field it does'nt take the value which i have typed, here is my code
final EditText ed1;
ed1=(EditText) findViewById(R.id.editText);
final String Fname=ed1.getText().toString();
final EditText ed2;
ed2=(EditText)findViewById(R.id.editText2);
final String Lname=ed2.getText().toString();
final EditText ed3;
ed3=(EditText)findViewById(R.id.editText3);
final String Email=ed3.getText().toString();
final EditText ed4;
ed4=(EditText)findViewById(R.id.editText4);
final String Password=ed4.getText().toString();
Button btn3;
btn3=(Button) findViewById(R.id.button3);
btn3.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
if (ed1.getText().toString().equalsIgnoreCase(""))
{
// show message/toast for empty name
Toast.makeText(getApplicationContext(), "Enter the fname", Toast.LENGTH_LONG).show();
}
else if (ed2.getText().toString().equalsIgnoreCase(""))
{
// show message/toast for empty Surname
Toast.makeText(getApplicationContext(), "Enter the lname", Toast.LENGTH_LONG).show();
}
else if (ed3.getText().toString().equalsIgnoreCase(""))
{
// show message/toast for empty Email
Toast.makeText(getApplicationContext(), "Enter the Email", Toast.LENGTH_LONG).show();
}
else if(ed4.getText().toString().equalsIgnoreCase(""))
{
// If above all conditions are false means all fields are not empty so put your action here
Toast.makeText(getApplicationContext(), "enter the Password", Toast.LENGTH_LONG).show();
}
else
{
Toast.makeText(getApplicationContext(), Fname, Toast.LENGTH_LONG).show();
System.out.println(Fname);
register(Fname, Lname, Email, Password);
}
}
});
}