如何在 IntelliJ 中调试时修改列表值
How to modify a List value while debugging in IntelliJ
我需要在调试应用程序期间更改变量。到目前为止,它只是可以直接设置的基本变量。现在我需要清除一个数组,以便 isEmpty()
returns true;
ArrayList<String> someList = new ArrayList<String>;
someList.add("1");
...
if(someList.isEmpty()){ //break point
//need to enter here
}
在 intellij 调试器中我看到:
someList={ArrayList@4271} size=1
我使用了调试器的'setValue'方法并尝试:new ArrayList<String>()
或someList = new ArrayList<String>()
这导致
someList={ArrayList@4339} size=0
但是,如果我继续,我会在调用 isEmpty() 时收到 NullPointerException。所以我的问题是:如何在没有 NPE 的情况下注入一个空的 ArrayList?
NPe 的文本是:java.lang.NullPointerException: Attempt to invoke interface method 'boolean java.util.List.isEmpty()' on a null object reference
您是否在 Windows 上尝试在调试期间使用 "Evaluate expression"(Alt + F8” ) ?
在此window你可以写:
someList.clear();
或
someList = new ArrayList<String>();
它应该可以解决问题。
在if(someList.isEmpty())
处停止断点,按ALT + F8(计算表达式),输入someList.clear()
, 按 Evaluate
继续调试。现在肯定会进入if条件
我有这个问题,但我正在使用 Kotlin,
你可以做到 (someList as ArrayList<*>).clear()
我需要在调试应用程序期间更改变量。到目前为止,它只是可以直接设置的基本变量。现在我需要清除一个数组,以便 isEmpty()
returns true;
ArrayList<String> someList = new ArrayList<String>;
someList.add("1");
...
if(someList.isEmpty()){ //break point
//need to enter here
}
在 intellij 调试器中我看到:
someList={ArrayList@4271} size=1
我使用了调试器的'setValue'方法并尝试:new ArrayList<String>()
或someList = new ArrayList<String>()
这导致
someList={ArrayList@4339} size=0
但是,如果我继续,我会在调用 isEmpty() 时收到 NullPointerException。所以我的问题是:如何在没有 NPE 的情况下注入一个空的 ArrayList?
NPe 的文本是:java.lang.NullPointerException: Attempt to invoke interface method 'boolean java.util.List.isEmpty()' on a null object reference
您是否在 Windows 上尝试在调试期间使用 "Evaluate expression"(Alt + F8” ) ?
在此window你可以写:
someList.clear();
或
someList = new ArrayList<String>();
它应该可以解决问题。
在if(someList.isEmpty())
处停止断点,按ALT + F8(计算表达式),输入someList.clear()
, 按 Evaluate
继续调试。现在肯定会进入if条件
我有这个问题,但我正在使用 Kotlin,
你可以做到 (someList as ArrayList<*>).clear()