Solution 1 :
If you don’t need any formatting just do:
setText("${destination.amount}")
Problem :
How do I call setText() using float data type? I have already tried this
if (response.isSuccessful) {
val destination = response.body()
destination?.let {
client_names.setText(destination.client_name)
product_names.setText(destination.product_name)
amounts.setText(String.valueOf(destination.amount)) ----->
prices.setText(String.valueOf(destination.price)) ----->
comments.setText(destination.comment)
collapsing_toolbar.title = destination.client_name + destination.product_name
}
I have tried this answer from this link
How to call setText() using a Float data type?
but I get this error
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.smartherd.globofly, PID: 8999
java.lang.NumberFormatException: empty String
at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1842)
at sun.misc.FloatingDecimal.parseFloat(FloatingDecimal.java:122)
at java.lang.Float.parseFloat(Float.java:451)
at com.smartherd.globofly.activities.DestinationDetailActivity$loadDetails$1.onResponse(DestinationDetailActivity.kt:58)
at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run(ExecutorCallAdapterFactory.java:71)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
I/Process: Sending signal. PID: 8999 SIG: 9
Comments
Comment posted by deHaar
Doesn’t a
Comment posted by p2pdops
destination.amount.toString()
Comment posted by stackoverflow.com/a/8907890/6264949
Have you tried this.