I am having a problem with a project in android studio.
I don't know which function is changing my variable value and I want to see what's responsible for changing it.
Is there any way to see which function/constructor does modify the variable ?
I have already added the variable to the Watches, but that only shows when the value changes. So is there any way to see the function that does change it specifically after it has another value ?
Related
Sorry, but showing through images is much better, okay?
The explanation follows below:
But if you declare the entire variable as a global variable, the following error occurs:
Please, what to do so that the variable value inside the blue rectangle goes to the value inside the red rectangle variable, in the first image, in the Android?
You don't. A variable declared in a method is only visible in that method. You either need to make it a class level variable, or you need to find another way of doing things.
The reason you're seeing the NullPointerException is that you haven't called the function yet when you try to use the class level variable. That means the variable isn't set, so its the default value of null. And obviously you can't dereference a null variable.
Your problem here is you have some circular logic. You're trying to set a change listener to a firebase reference, but trying to get the id of the reference inside the change listener. That's not going to work- how do you get a reference when you don't know what you're trying to get a reference to? Either you missed some other way to get that id, or you need to rethink what you're doing.
Is there any way to have conditional Debug in android studio?
for example I wanna go to debug mode when a specific variable value is.
for example:
for(MyClass myclass: ClassList){
String title = myclass.gettitle(); // this is where break point is
}
Before that I do not need the debug mode. I just wanna examine the app on that exact value. for example when title="KickBoxing" in this case I should check the variable value and if it is not my required value I should press F9 to go to next value. maybe this takes 50 times to get to my desired value.
It is possible to add a condition for a breakpoint. Add a breakpoint, as you normally do, and click with the right mouse button on it. You will be prompt with a dialog. In the condition you can put some java code.
E.g. you could put "kickBoxing".equals(title)
this way the debugger will stop on that breakpoint only when the condition is true.
(photo taken from http://javafortesters.com/)
You can do that with Android Studio:
Set a breakpoint on the line you need.
Right-click on the breakpoint
Paste your condition into the field named Condition
For example, your condition should be like myclass.gettitle().equals("KickBoxing")
What is the shortcut key to find that where is the particular global variable Initializing in android studio project.
Place your cursor on the variable and then press Alt+F7 for the Find Useages command. In the Find Usages result, look for "Value write". Expanding that category will show all the places where the variable is assigned, which includes initialization.
If you middle-mouse-click any of your variables it takes you to the delcaration. If you middle click it again, it pops up a window with every usage. Alt+F7 works too.
There are scenarios in feature files wherein I've use the text "Foo" and on click its open a new page. this text sometime changes to "Foo1" or "Foo2" or to something else. to avoid line by line change in feature file for "Foo" to "Foo1" or "Foo2" is there any way that I can globally declare variable in top/bottom of the feature file where I can set the required text in variable on fly and I shall start executing my test instantly?
This change exist in many feature files and around 1000 lines in feature file. To get solution for this, I try on setting environment variables but I couldn't reach all the way till end this issue to solve. So can anyone help me on this?
Thanks in advance
What if you do the replacement in your step implementation instead? Then you could have the desired value in a separate file or pass it as arguments. That way you don't need to hard code the values.
Could scenario outlines help you in any way or is the value only changing depending on external changes?
My first thought was scenario outlines like #homaxto said.
Then I thought you might want to affect it by which system you are connected to. You can do this through configuration. I have done this with Fig_Newton.
You can either set an environment varaible or use one in the commandline. Or you can use #hook type tags. With a hook tag, you can have a tag at the top of a feature file that you can use to set a variable that affects how the steps operate (but it needs to be handled inside the step).
I know I could set a breakpoint at every line where my code changes the variable, but is there an option such as right-clicking a variable (to "Add to Watches") that would stop when a variable changes value?
I think C++ has this option. See this.
And Eclipse? See this.
Is this implemented in AS?
You can break on value changes of some variables in Android Studio 1.1.0.
Android Studio calls them 'Java Field Watchpoints'.
From the breakpoints windows, (Run -> "View breakpoints...") or Ctrl+Shift+F8,
you can add "Java Field Watchpoints" from the plus in the top left corner, and then select your class and variable.
If the goal is simply to set a watchpoint where execution halts if a variable's value changes, there are two methods:
Pressing Ctrl-shift-F8 to set a watchpoint brings up this dialog:
That looks more powerful but it's confusing because it lacks the option I need; and there's an extra step: filling in the dialog box below:
Once you fill it in correctly, you get the same options for stopping execution as in the simpler method below:
Define the variable on one line ending with a semicolon.
Left-click in the area where you set a normal breakpoint and up pops a dialog box.
Choose options to suit your needs.
Any instance where the value of the variable prefDbExists changes, execution will pause as at any "normal" (unconditional) breakpoint. And that's all I needed when I asked the original question.
EDIT: Fully qualified class name is {package name}.{class name})
What you seek for is commonly known as "WatchPoint".
You will find detailed answer and examples on the doc. page of JetBrains - IntelliJ - Idea which is the basis for Android Studio.
https://www.jetbrains.com/help/idea/2016.3/creating-field-watchpoints.html
For me this works perfectly !
Add a Kotlin Field Watchpoint by clicking on the space next to the line number for the field declaration in Android Studio. Select Kotlin Field Watchpoint from the Set Breakpoint menu. You will now get a breakpoint whenever that value changes.