简体   繁体   中英

Java code evaluation (IntelliJ IDE), use toString() in some point?

When evaluating object initialization, toString nullPointerException appear.

Method threw 'java.lang.NullPointerException' exception. Cannot evaluate XXXX.toString()

Code example which recreates this issue:

Car car = carUtils.objectMapper.readValue(new File(pathTo("carProperties.json")), Car.class); 

Why is that happens? is the evaluation done using toSting() invocations?

I have discovered the root cause for this behavior.

You can choose in what way IntelliJ evaluation will display the data: the result can be the Object or toString evaluation . Therefore the error i had experienced, View as->toString was used, while not all the objects had toString implemented. Hope it will help someone in the future.

在此处输入图片说明

You can update the display type for a variable by right clicking on the variable (inside the variables window of the debugger) and clicking on 'View as'

If you don't want to update it manually each time, you can change it in IntelliJ properties following this steps

也许您覆盖了hashCode()方法并且hashCode()返回null

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM