G
G
glodev2020-02-18 14:23:16
Java
glodev, 2020-02-18 14:23:16

NullPointerException, Kotlin, Square root of BigDecimal?

val epsilon = 0.000000000000000000000001.toBigDecimal()
private val accuracy = MathContext(1000)
private val maxIteration = maxIteration
private fun doElipticK():BigDecimal{
        println(epsilon)
        val epsilonSqrt = epsilon.sqrt(accuracy)

So the code works, but as soon as we add 0.0000000000000000000000001 to the number, we get an exception, in which direction should we look?
val epsilon = 0.000000000000000000000002.toBigDecimal()
private val accuracy = MathContext(1000)
private val maxIteration = maxIteration
private fun doElipticK():BigDecimal{
        println(epsilon)
        val epsilonSqrt = epsilon.sqrt(accuracy)

NullPointerException

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
mayton2019, 2020-02-19
@mayton2019

What line is your NPE on?

A
Alex Avaj, 2020-02-20
@sandroisu

Eh kotlin, kotlin...
To begin with, it would be possible to debug so that people here have an understanding on which line your code is crashing. Based on my guesses (I don’t know Kotlin), doEliptick is some kind of method that it does hidden from us. I put 5 kopecks on the fact that if this is a method, then it falls in it.
In general, you need to debug, and then you yourself will understand what the problem is. You will not understand - throw here the full code and a line on which falls.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question