0
\$\begingroup\$

I made the game in android in this game i want first login and registration through JSON object. I have a API link where JSON Object send data from that url to the server but in my server i get the data something like this android.widget.EditText{b68c34b VFED..CL. ...........
android.widget.EditText{e1e3128 VFED..CL. ...........

Here is the code :-

RegistrationActivity.java

public class RegisterActivity extends Activity {
    private static final String TAG = RegisterActivity.class.getSimpleName();
    String url = "http://codexpertise.com/codexpertise.com/apitest/signup.php";
    private Button btnRegister;
    private Button btnLinkToLogin;
    private EditText inputFullName;
    private EditText inputEmail;
    private EditText inputPassword;
    private ProgressDialog pDialog;
    private SessionManager session;
    private SQLiteHandler db;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        inputFullName = (EditText) findViewById(R.id.name);
        inputEmail = (EditText) findViewById(R.id.email);
        inputPassword = (EditText) findViewById(R.id.password);
        btnRegister = (Button) findViewById(R.id.btnRegister);
        btnLinkToLogin = (Button) findViewById(R.id.btnLinkToLoginScreen);

        // Progress dialog
//        pDialog = new ProgressDialog(this);
//        pDialog.setCancelable(false);

        // Session manager
        session = new SessionManager(getApplicationContext());

        // SQLite database handler
        db = new SQLiteHandler(getApplicationContext());

        // Check if user is already logged in or not
        if (session.isLoggedIn()) {
            // User is already logged in. Take him to main activity
            Intent intent = new Intent(RegisterActivity.this,
                    MainActivity.class);
            startActivity(intent);
            finish();
        }

        // Register Button Click event
        btnRegister.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                String name = inputFullName.getText().toString().trim();
                String email = inputEmail.getText().toString().trim();
                String password = inputPassword.getText().toString().trim();
                compare_version();

                if (!name.isEmpty() && !email.isEmpty() && !password.isEmpty()) {
                } else {

                    Toast.makeText(getApplicationContext(),
                            "Please enter your details!", Toast.LENGTH_LONG)
                            .show();


                }
            }
        });

        // Link to Login Screen
        btnLinkToLogin.setOnClickListener(new View.OnClickListener() {

            public void onClick(View view) {
                Intent i = new Intent(getApplicationContext(),
                        LoginActivity.class);
                startActivity(i);
                finish();
            }
        });

    }


    /**
     * Function to store user in MySQL database will post params(tag, name,
     * email, password) to register url
     */
    private void registerUser(final String name, final String email,
                              final String password) {
        // Tag used to cancel the request
        String tag_string_req = "req_register";

        pDialog.setMessage("Registering ...");
        //  showDialog();

    }

    private void compare_version() {
        JSONObject parameters = new JSONObject();

        try {
            parameters.put("type", "signup");
            parameters.put("username", inputFullName);
            parameters.put("email", inputEmail);
            parameters.put("mobileno", "8871539601");
            parameters.put("password", inputPassword);


        } catch (JSONException e) {
        }
        JsonObjectRequest req = new JsonObjectRequest(Request.Method.POST, url, parameters,
                new Response.Listener<JSONObject>() {
                    @Override
                    public void onResponse(JSONObject response) {
                        try {
                            JSONObject jsonObject = response;
                            String resp_code = jsonObject.getString("resp_code");
                            String resp_msg = jsonObject.getString("res_response");
                            System.out.println("response version =====" + response);

                            resp_code = "200";
                            if (resp_code.compareTo("200") == 0) {
                                System.out.println("response msg==" + resp_msg);
                                Toast.makeText(RegisterActivity.this, "response msg==" + resp_msg, Toast.LENGTH_SHORT).show();

                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
                VolleyLog.e("Error: ", error.getMessage());

            }
        });
        MyApplication.getInstance().addToRequestQueue(req);
    }

MyApplication.java

public class MyApplication extends Application {

    public static final String TAG = MyApplication.class
            .getSimpleName();

    private RequestQueue mRequestQueue;

    private static MyApplication mInstance;
    /*deprecated*/




    @Override
    public void onCreate() {
        super.onCreate();
        mInstance = this;
    }

    public static synchronized MyApplication getInstance() {
        return mInstance;
    }

    public RequestQueue getRequestQueue() {
        if (mRequestQueue == null) {
            mRequestQueue = Volley.newRequestQueue(getApplicationContext());
        }

        return mRequestQueue;
    }
    public <T> void addToRequestQueue(Request<T> req) {
        req.setTag(TAG);
        getRequestQueue().add(req);
    }



}
\$\endgroup\$
0
\$\begingroup\$

The problem is here:

parameters.put("type", "signup");
parameters.put("username", inputFullName);
parameters.put("email", inputEmail);
parameters.put("mobileno", "8871539601");
parameters.put("password", inputPassword);

inputFullName, inputEmail, and inputPassword are EditText classes. They are not pure text. The fix is to get the text from these objects using .getText():

parameters.put("type", "signup");
parameters.put("username", inputFullName.getText());
parameters.put("email", inputEmail.getText());
parameters.put("mobileno", "8871539601");
parameters.put("password", inputPassword.getText());

You might need to add .toString() as well:

parameters.put("type", "signup");
parameters.put("username", inputFullName.getText().toString());
parameters.put("email", inputEmail.getText().toString());
parameters.put("mobileno", "8871539601");
parameters.put("password", inputPassword.getText().toString());
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.