4 ms·
I don't see that many NPE in kotlin these days but pretty sure that on java/Android I get a useful error message. Is that an ART/Dalvik feature ?
by on_and_off 8y ago
I don't see that many NPE in kotlin these days but pretty sure that on java/Android I get a useful error message.
Is that an ART/Dalvik feature ?
- m0skit0 8y agoI don't remember getting any useful error message, but I've been using Kotlin for 3 years now, so I might not remember correctly. Can you post a stacktrace of what you're referring to?
- on_and_off 8y agoas stated in another comment, you get : s exception: Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.Integer.toString()' on a null object reference the name of the method causing the crash (toString in that sample) + the line number and location thanks to the stacktrace (although in some rare case it is 100% accurate, but still pretty close, maybe that's due to runtime inlining) and it is very trivial to know where the exception comes from.
- pkulak 8y ago> I don't see that many NPE in kotlin these days Nice humble brag. :D
- kllrnohj 8y ago> Is that an ART/Dalvik feature ? Yes, ART has had this for a few years now. For example in Oreo this code: static Integer nums[] = new Integer[100]; public static String stabSelf() { return nums[new Random().nextInt(100)].toString(); } Will produce this exception: Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.Integer.toString()' on a null object reference