Hey,
I’m building Android app right now, and I found a strange problem occurred in kotlin 1.2.51:
Handler(Looper.getMainLooper()).post {
for (line in lines) {
// do stuff
}
// do smothing else
}
when I’m running this code (lines
is an empty mutable list) the program crashing.
In the log, it says that it crashed a few lines before that.
But the strange thing is that when I removed the for (line in lines)
loop (loop over empty list!!), it runs just fine.
2018-07-18 00:13:40.660 16387-17204/com.my.app E/AndroidRuntime: FATAL EXCEPTION: Thread-28
Process: com.my.app, PID: 16387
kotlin.KotlinNullPointerException
at com.my.app.fragments.SomeFragment$onCreate$2.run(SomeFragment.kt:102)
at java.lang.Thread.run(Thread.java:764)
This is the java decompiled:
(new Handler(Looper.getMainLooper())).post((Runnable)(new Runnable() {
public final void run() {
Iterator var2 = lines.iterator();
while(var2.hasNext()) {
// do stuff
}
// do smothing else
}));
How can I manage to solve this problem? or at least find out why this is happening…
Thanks.