• 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.
 
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;
}
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones