是否可以在运行时监视变量? [英] Is it possible to watch variables at runtime?

查看:64
本文介绍了是否可以在运行时监视变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我了解调试的基础知识,并且我知道可以将监视添加到变量中,以在给定条件下停止程序的执行.但是我不想每次需要查看变量值时都停止程序.我也不想将每个相关变量的值记录到logcat中……我只希望像在断点处那样,仅在运行时才能看到它们的值.

I know the basics of debugging, and I know I can add watches to a variable that stop the program's execution on a given condition. But I didn't want to stop the program every time I need to see the value of a variable. Neither I want to log the value of every relevant variable into logcat... I only wanted to see their values like I do at breakpoints, only in runtime.

我正在Android Studio中为Android编程.

I'm programming Android, in Android Studio.

感谢您的帮助!

推荐答案

当程序在断点处停止时,单击调试器菜单最右边的图标(请参见下图).您可以在此窗口中输入方法或变量名称,然后查看它们的名称.

When your program has stopped on a breakpoint click the icon at the far right of the debugger menu (see image below). You can type in methods or variable names into this window and see what they would be.

您可以键入任何喜欢的表达式(只要它在破坏代码的范围之内)并输入所有硬编码的值或对象,而无需重新运行项目.

You can type any expression you like (as long as it is within the scope of where you broke your code) and input any hard-coded values or objects all without re-running your project.

要将变量添加到监视列表

首先在要查看特定变量的类中放置一个断点.运行代码,一旦它从变量"窗口框架到达断点,您应该会看到所有可访问的变量.只需选择您要观看的手表,然后右键单击并从下拉菜单中选择添加到手表".

Start by putting a break point in the class where you'd want to watch a specific variable. Run the code and once it hits your breakpoint from the Variables window frame you should see all of the variables that are accessible. Simply choose the one you'd want to watch and then right click and choose "Add to watches" from the drop-down.

进行调试,您将根据代码在适当的情况下从监视"窗口框架中看到变量.

Keep debugging and you should see the variable from the Watches window frame update when appropriate based on your code.

这篇关于是否可以在运行时监视变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆