Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Static variable fields not visible in debbuger

Hi I've got a very simple class defined like this

public class Pokus {


    public static String loginToken;
    public String neco = "neco";

    public Pokus() {
    }

    public static String getLoginToken() {
        return loginToken;
    }

    public static void setLoginToken(String loginToken) {
        Pokus.loginToken = loginToken;
    }
}

When I create an instance of this class

Pokus pokus = new Pokus();
pokus.setLoginToken("bla1212");

In a debugger I can see that object pokus has a field/variable called "neco" but not that static variable "loginToken".

debbuger in Android Studio

Is there any way to see static variables as well as the non-static ones?

like image 859
Adam Novakovi Avatar asked Sep 21 '16 11:09

Adam Novakovi


People also ask

How do I show static variables in Eclipse debugger?

Variables. We can see the values of variables during the execution under the Variables view. In order to see the static variables, we can select the drop-down option Java -> Show Static Variables. Using the variables view, it's possible to change any value to the desired value during the execution.

How do you declare static variables?

C++ Programming Class variables also known as static variables are declared with the static keyword in a class, but outside a method, constructor or a block. There would only be one copy of each class variable per class, regardless of how many objects are created from it.


2 Answers

Thanks guys I knew all of this but didn't know that debugger is taking this into consideration. There is an option to show static field Settings > Build,Execution, Deployement > Debugger > Data Views > Java

like image 119
Adam Novakovi Avatar answered Oct 21 '22 07:10

Adam Novakovi


Debugger shows it properly, pokus is instance of class Pokus so it have standard method and properties from class Pokus, static methods and properties are in Class not in instance of Class. Static properties are shared for every object created from class Pokus ( or for every component in program if their are public ) so debugger properly not shows them as properties of single instance.

To show static variable examine class not instance. When debugger stops on breakpoint You can use console and write Pokus.someStaticVar and You will see current value. Console is available in debugger - http://imgur.com/a/nHfEo.

like image 22
Maciej Sikora Avatar answered Oct 21 '22 07:10

Maciej Sikora