-1

I have a class to take data from a database and every time I create a variable in the debug mode the name of the variable appears with the message 'this' is not available and I cannot save any type of data in it.

public class DatosPerfilUsuario {


RequestQueue requestQueue;
SharedPreferencias sharedPreferencias = new SharedPreferencias();

String[] StringSplit;


public void RetirarPerfilUsuario(final Context context, final ImageView imageView, final EditText nombre, final EditText nombreusuario, final EditText sexo, final EditText edad, final EditText email, final EditText bio){

    StringRequest getRequest = new StringRequest(Request.Method.POST, DatosBase.CONEXION_DB_RETIRAR_PERFILUSUARIO, new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {
            if(response.equals("0")){

            }else {
               StringSplit = response.split("/");

            }

        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {

        }
    }) {
        protected Map<String,String> getParams(){
            Map<String, String>  params = new HashMap<String, String>();
            params.put("NombreUsuario",sharedPreferencias.obtenerValorString(context,"Usuario").toLowerCase());
            return params;
        }
    };
    requestQueue = Volley.newRequestQueue(context);
    requestQueue.add(getRequest);
}

Code This situation happens to me with each type of variable that I create int, string, bool ...

I have different classes that do the same, but the problem only arises in this.

I have looked for a solution to the problem in google but there is very little information about this problem, if someone has the solution or understands why this problem is due I would appreciate your help.

  • please take a look at https://stackoverflow.com/help/minimal-reproducible-example – SamuelTJackson Nov 28 '19 at 00:02
  • What happens if you set `var that = this` before the request, and then try to use `that` after the request in place of `this`? – nbixler Nov 28 '19 at 00:02
  • Images of code and error message are not useful. See [this Meta post](https://meta.stackoverflow.com/a/285557/62576) for a list of the many reasons we don't accept them. Code is text, and can be copied and pasted directly into your question. Please [edit] to provide a [mcve] that demonstrates the issue. – Ken White Nov 28 '19 at 00:10

1 Answers1

0

UPDATED It looks like this is not preventing you from compiling and running the code, only that you can't view the variable's contents in the debug window. Sorry. This is not uncommon. The debugger can't determine the this in the current context.

It looks like you may be using Android Studio? If so, check this: https://stackoverflow.com/a/37273436/12431728

OLD / WRONG Your Response.Listener<String> is an anonymous class, so this refers to the anonymous class. Since StringSplit is a field of the outer class, you should be able to access it as:

OuterClassName.this.StringSplit = ...

Where OuterClassName is the name of the class that contains this code (and StringSplit).

Matt U
  • 4,970
  • 9
  • 28
  • Thanks for the answers, but when i try to put the result of the variable in an EditText i get an error that the variable is empty. I use this method in other classes and it works fine, I will remove this class and try to create it from scratch again. – Marcos Mariño Nov 28 '19 at 00:45
  • Just below the StringSplit, in the example I didn't put it – Marcos Mariño Nov 28 '19 at 00:53