• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

String definition error

Java:
public String SolicitudServidor(final Activity activity, final String Type, final String Name, final String Surname, final String Username, final String Password){
    String URL, Response;
    if(Type.equals("Register")){
        URL="http://web-androidapp.000webhostapp.com/androidapp/registerUser.php?name="+Name.replaceAll(" ", "%20")+"&surname="+Surname.replaceAll(" ", "%20")+"&username="+Username+"&password="+Password;
    }else if(Type.equals("Check")){
        URL="http://web-androidapp.000webhostapp.com/androidapp/CheckUser.php?username="+Username;
    }
    StringRequest stringRequest=new StringRequest(Request.Method.POST, URL, new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {
            try{
                JSONObject jsonObject=new JSONObject(response);
                Response=jsonObject.getString("Ok");
            }catch (JSONException e){
                e.printStackTrace();
                MostrarPopUp("Error", activity);
            }
        }
    },
            new Response.ErrorListener(){
                @Override
                public void onErrorResponse(VolleyError error){
                    MostrarPopUp("Error", activity);
                }
            });
    RequestQueue requestQueue= Volley.newRequestQueue(activity);
    requestQueue.add(stringRequest);
    return Response;
}

I'm getting an error when using the URL and Response variables. Cannot resolve symbol 'URL' or 'Response'. If I define the variable as final String it appears: Variable 'URL' or 'Response' might not have been initialized.
 
Now:
(String Response="";) Variable Response is accessed from within inner class needs to be declared final
(final String Response="";) Cannot assign a value to final variable
 
Last edited:
Placing it as a global value I get the previous answer. That is to say:
When entering a username the answer is "null". Then when entering a different one, I get the answer from the previous one in "available" or "not available."
 
When entering a username the answer is "null". Then when entering a different one, I get the answer from the previous one in "available" or "not available."
I don't get you. Can you elaborate more?
 
Username: user1 (available).
Response: null.

Username: user2 (non available).
Response: available

Username: user1 (available).
Response: non available
 
Java:
String URL = "";   // set as global
String  Response="";  // set as global

public String SolicitudServidor(final Activity activity, final String Type, final String Name, final String Surname, final String Username, final String Password){
    if(Type.equals("Register")){
        URL="http://web-androidapp.000webhostapp.com/androidapp/registerUser.php?name="+Name.replaceAll(" ", "%20")+"&surname="+Surname.replaceAll(" ", "%20")+"&username="+Username+"&password="+Password;
    }else if(Type.equals("Check")){
        URL="http://web-androidapp.000webhostapp.com/androidapp/CheckUser.php?username="+Username;
    }
    StringRequest stringRequest=new StringRequest(Request.Method.POST, URL, new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {
            try{
                JSONObject jsonObject=new JSONObject(response);
                Response=jsonObject.getString("Ok");
            }catch (JSONException e){
                e.printStackTrace();
                MostrarPopUp("Error", activity);
            }
        }
    },
            new Response.ErrorListener(){
                @Override
                public void onErrorResponse(VolleyError error){
                    MostrarPopUp("Error", activity);
                }
            });
    RequestQueue requestQueue= Volley.newRequestQueue(activity);
    requestQueue.add(stringRequest);
    return Response;
}
 
Yes!
Placing it as a global value I get the previous answer. That is to say:

Username: user1 (available).
Response: null.

Username: user2 (non available).
Response: available

Username: user1 (available).
Response: non available
 
Back
Top Bottom