0

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:

This is my 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);
                }


            }

        });
    }
HariPriya
  • 81
  • 1
  • 1
  • 5
  • post error msg and the stacktrace – ΦXocę 웃 Пepeúpa ツ Feb 22 '16 at 04:23
  • Looks like `client` might be null. – Andreas Feb 22 '16 at 04:23
  • which client is null ? – HariPriya Feb 22 '16 at 04:30
  • You never want to try to pull text from an EditText without checking to make sure its not empty, because if there is not content in the box it will return null when you try to get text. You should use if(ed1.getText().toString().trim().length() > 0){set your variable to it} – ChonBonStudios Feb 22 '16 at 04:40
  • Also, if your users are entering text and then hitting register, you are pulling the text from the edittext when the activity sets up, so its pulling nothing the user enters. You should move the setting up of the variables to be passed to the register() method to inside the onClick() method block. – ChonBonStudios Feb 22 '16 at 04:42
  • i have passed all the parameters inside the register() method only – HariPriya Feb 22 '16 at 05:11
  • @HariPriya your code formate is wrong. get all parameters like Fname,Lname,Email,Password etc in Onclick event. ckeck my answer http://stackoverflow.com/questions/30029257/checking-empty-textedit/30029801#30029801 – Nils Feb 22 '16 at 05:21
  • Still i am getting the same error i modified my code according to your format.@NilsPatel – HariPriya Feb 22 '16 at 06:50

0 Answers0