第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Android studio 應(yīng)用程序崩潰錯誤:AndroidRuntime:

Android studio 應(yīng)用程序崩潰錯誤:AndroidRuntime:

holdtom 2023-11-01 22:00:56
我制作了一個 Android 應(yīng)用程序,當我嘗試應(yīng)用優(yōu)惠券代碼時,在模擬器中進行測試時就會崩潰。我很困惑,無法找出錯誤。這是我的 Android 應(yīng)用程序日志:E/AndroidRuntime: FATAL EXCEPTION: main    Process: com.dhruv.shop, PID: 1790    java.lang.NumberFormatException: Invalid int: "1,2,11"        at java.lang.Integer.invalidInt(Integer.java:138)        at java.lang.Integer.parse(Integer.java:410)        at java.lang.Integer.parseInt(Integer.java:367)        at java.lang.Integer.parseInt(Integer.java:334)        at com.dhruv.shop.fragments.Checkout.applyCoupon(Checkout.java:1760)        at com.dhruv.shop.fragments.Checkout$26.onResponse(Checkout.java:1573)        at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run(ExecutorCallAdapterFactory.java:70)        at android.os.Handler.handleCallback(Handler.java:739)        at android.os.Handler.dispatchMessage(Handler.java:95)        at android.os.Looper.loop(Looper.java:148)        at android.app.ActivityThread.main(ActivityThread.java:5417)        at java.lang.reflect.Method.invoke(Native Method)        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)I/Process: Sending signal. PID: 1790 SIG: 9Application terminated.我發(fā)現(xiàn)我的錯誤代碼指向 checkout.java 文件中的 applycoupon 方法,任何人都可以找出導致下面代碼中的錯誤的原因,并盡快給我解決此錯誤的方法
查看完整描述

1 回答

?
慕村225694

TA貢獻1880條經(jīng)驗 獲得超4個贊

首先使用將數(shù)據(jù)轉(zhuǎn)換為字符串,然后String解析數(shù)字 字符串數(shù)據(jù),例如:-numericreplaceAll

Integer.parseInt(stringData.replaceAll(",","")); // this should avoid the crash !

但要獲取類別 ID 列表,您應(yīng)該使用以下split方式,:-

String[] categoryIds = checkoutItemsList.get(i).getCustomersBasketProduct().getCategoryIDs().split(",");

然后將字符串數(shù)組轉(zhuǎn)換為int數(shù)組

int[] intIds = Arrays.stream(categoryIds).mapToInt(Integer::parseInt).toArray();


查看完整回答
反對 回復 2023-11-01
  • 1 回答
  • 0 關(guān)注
  • 264 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號