Catherine Lagoon Catherine Lagoon - 5 months ago 16
Android Question

For some reason when I write getparams it doesn't do what it is supposed to do?

This is what is meant to happen:
enter image description here

and when you just write "getpar" it is meant to give the option:
enter image description here

however for me when I do it
enter image description here

nothing happens

and it throws an AuthFailureError

package com.name.name;

import com.android.volley.AuthFailureError;
import com.android.volley.Response;
import com.android.volley.toolbox.StringRequest;

import java.util.HashMap;
import java.util.Map;

/**
* Created by p on 17/06/2016.
*/
public class RegisterRequest extends StringRequest {

private static final String REGISTER_REQUEST_URL = "http://name.comli.com/Register.php";
private Map<String, String> params;

public RegisterRequest(String name, String username, int age, String password, Response.Listener<String> listener) throws AuthFailureError {
super(Method.POST, REGISTER_REQUEST_URL, listener, null);
params = new HashMap<>();
params.put("name", name);
params.put("username", username);
params.put("password", password);
params.put("age", age+ "");

getparams


Thankyou and help would be appreciated into how to resolve this error.=)
public class RegisterActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);

final EditText etAge = (EditText) findViewById(R.id.etAge);
final EditText etUsername = (EditText) findViewById(R.id.etUsername);
final EditText etPassword = (EditText) findViewById(R.id.etPassword);
final EditText etName = (EditText) findViewById(R.id.etName);
final Button bRegister = (Button) findViewById(R.id.bRegister);

bRegister.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final String name = etName.getText().toString();
final String username = etUsername.getText().toString();
final String password = etPassword.getText().toString();
final int age = Integer.parseInt(etName.getText().toString());

Response.Listener<String> responseListener = new Response.Listener<String>(){

@Override
public void onResponse(String response) {
try {
JSONObject jsonResponse = new JSONObject(response);
boolean success = jsonResponse.getBoolean("success");

if (success) {
Intent intent = new Intent(RegisterActivity.this, LoginActivity.class);
RegisterActivity.this.startActivity(intent);
}else{
AlertDialog.Builder builder = new AlertDialog().Builder(RegisterActivity.this);
builder.setMessage("Register Failed")
.setNegativeButton("Retry", null)
.create()
.show();
}

} catch (JSONException e) {
e.printStackTrace();
}

}

};

registerRequest = new RegisterRequest(name,username,age,password,responseListener);


RequestQueue queue = Volley.newRequestQueue(RegisterActivity.this);
queue.add(registerRequest);

}
});



}
}

Answer

From what it seems you are typing it in the constructor. Try typing it out of the constructor? And I dont really know what you are trying to do. To me it looks like there is a function, and in the next picture the function is gone suddenly but there is an autocomplete for it.

So are you sure your parent class has the getParams function? And is it public or protected? My knowledge on inheritance isnt that great anymore, but I remember having problems with private functions.

As you can see this is your code

public RegisterRequest(String name, String username, int age, String password, Response.Listener<String> listener) throws AuthFailureError {
    ....

   getparams 

But the bracket never closes! So try this:

    public RegisterRequest(String name, String username, int age, String password, Response.Listener<String> listener) throws AuthFailureError {
        super(Method.POST, REGISTER_REQUEST_URL, listener, null);
        params = new HashMap<>();
        params.put("name", name);
        params.put("username", username);
        params.put("password", password);
        params.put("age", age+ "");
}

And then type getparams. I dont know if it works, but atleast you have a closed constructor.

Comments