+ 1

Null Pointer Exception in Shipping Calculator. For JAVA and KOTLIN experts...

From nowhere this error is getting popped up for me. Kindly help me overcome this: CODE:- fun shippingCost(amount: Double, international: Boolean): Double { var a: Double if(international==true) { if(amount>=75.0) { a=amount*0.15 if(a>50.0) { a=50.0 return a } else { return a } } } if(amount>=75.0 && international==false) { a=0.0 return a } else { a=amount/10.0 return a } return 0.0 } fun main(args: Array<String>) { val total = readLine()!!.toDouble() val international = readLine()!!.toBoolean() println(shippingCost(total, international)) } ERROR:- Exception in thread "main" java.lang.NullPointerException at File0Kt.main(file0.kt:33)

30th Mar 2021, 3:39 AM
Vishnuvasan Srinivasan
Vishnuvasan Srinivasan - avatar
14 Réponses
+ 6
Vishnuvasan Srinivasan This is for kotlin fun shippingCost(amount: Double, international: Boolean): Double { if(international == true){ if(amount * 0.15 < 50){ return amount * 0.15 }else{ return 50.0 } }else{ if(amount > 75){ return 0.0 }else{ return amount * 0.1 } } } fun main(args: Array<String>) { val total = readLine()!!.toDouble() val international = readLine()!!.toBoolean() println(shippingCost(total, international)) }
30th Mar 2021, 4:15 AM
❤️😍Prerana😍❤️
❤️😍Prerana😍❤️ - avatar
+ 1
Sathe Prerana Satish Thank you very much sis...
30th Mar 2021, 4:16 AM
Vishnuvasan Srinivasan
Vishnuvasan Srinivasan - avatar
0
I tried your code but didn't get that error. Did you put the values on separate line when giving input before run? https://code.sololearn.com/WhiNb9BkJUVC/?ref=app
30th Mar 2021, 3:48 AM
Ipang
0
Ipang Yes I did. If you got the output can you share that?
30th Mar 2021, 3:50 AM
Vishnuvasan Srinivasan
Vishnuvasan Srinivasan - avatar
0
Ok give me some input examples to test which triggered the error on your side. Let me try to reproduce the symptom ...
30th Mar 2021, 3:52 AM
Ipang
0
Dude... All the test cases failed in my case.
30th Mar 2021, 3:53 AM
Vishnuvasan Srinivasan
Vishnuvasan Srinivasan - avatar
0
That's really bad Maybe someone who went through this task can help you out later.
30th Mar 2021, 3:58 AM
Ipang
0
Oh..😢
30th Mar 2021, 3:59 AM
Vishnuvasan Srinivasan
Vishnuvasan Srinivasan - avatar
0
I recall someone posted a question about this shipping cost problem. Maybe you can search for that one and see the solution.
30th Mar 2021, 4:02 AM
Ipang
0
Ipang Thanks bro...
30th Mar 2021, 4:03 AM
Vishnuvasan Srinivasan
Vishnuvasan Srinivasan - avatar
0
Yeah good luck finding bro ... 👌
30th Mar 2021, 4:04 AM
Ipang
0
Vishnuvasan Srinivasan Most welcome bro Is it works
30th Mar 2021, 4:17 AM
❤️😍Prerana😍❤️
❤️😍Prerana😍❤️ - avatar
0
Yes. It does.
30th Mar 2021, 4:18 AM
Vishnuvasan Srinivasan
Vishnuvasan Srinivasan - avatar
30th Mar 2021, 4:28 AM
❤️😍Prerana😍❤️
❤️😍Prerana😍❤️ - avatar