我在使用两个非0小数的double上遇到问题。 例如,如果我的两倍是15.00,就可以了,但是如果我的双重是15.55,我的应用就会崩溃。 这是在我的真实手机(Galaxy s8 +-API 26)上发生的,在android studio中的所有虚拟设备上,它都能与各种双打(15.00和15.55)配合使用。 有人可以帮忙吗?
我的代码:
DecimalFormat formatData = new DecimalFormat("#.##");
Menu_ID.add(Long.parseLong(menu.getString("Menu_ID")));
Menu_name.add(menu.getString("Menu_name"));
Menu_price50.add(Double.valueOf(formatData.format(menu.getDouble("Price_50"))));
if(Category_ID == 1) {
Menu_price100.add(Double.valueOf(formatData.format(menu.getDouble("Price_100"))));
}
Menu_image.add(menu.getString("Menu_image"));
崩溃日志
E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #2
Process: com.ayurmed.ayucom, PID: 23974
java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:353)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
at java.util.concurrent.FutureTask.run(FutureTask.java:271)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:764)
Caused by: java.lang.NumberFormatException: For input string: "14,5"
at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:2043)
at sun.misc.FloatingDecimal.parseDouble(FloatingDecimal.java:110)
at java.lang.Double.parseDouble(Double.java:539)
at java.lang.Double.valueOf(Double.java:503)
at com.ayurmed.ayucom.activities.ActivityMenuList.parseJSONData(ActivityMenuList.java:393)
at com.ayurmed.ayucom.activities.ActivityMenuList$getDataTask.doInBackground(ActivityMenuList.java:338)
at com.ayurmed.ayucom.activities.ActivityMenuList$getDataTask.doInBackground(ActivityMenuList.java:324)
at android.os.AsyncTask$2.call(AsyncTask.java:333)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:764)