gpt4 book ai didi

当语言环境不是英语时,Kotlin 崩溃

转载 作者:行者123 更新时间:2023-12-02 12:53:42 25 4
gpt4 key购买 nike

首先,我是编程新手,我阅读了其他帖子,但都没有解决我的问题。

我有一个与本地人一起使用三种语言的应用程序:罗马尼亚语、英语、西类牙语
该应用程序有 2 个事件:主要是数据填充另一个计算结果。
当我在英语以外的其他语言环境中测试应用程序时,会崩溃。

问题是在英文应用程序中表现非常好,在调试的其他语言环境中我得到致命异常:

  package com.example.sportbetodds
import android.content.Context
import android.content.Intent
import android.content.res.Configuration
import android.os.Build
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.support.annotation.RequiresApi
import kotlinx.android.synthetic.main.activity_main.*
import java.util.*
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
var ntm = etntm.text
var gda= etntGDA.text
var gdd = etntGDD.text
var ntmM = etntmM.text
var gdaMG = etMGDA.text
var gdaMO = edMGDD.text
var gpaMG = edMGPA.text
var gpaMO =etMGPD.text
try {
btCalT.setOnClickListener {
/** Statistici din liga **/
val intent = Intent(this@MainActivity, Rezultate::class.java)
//acasa date
var ntmA = ntm.toString().toBigDecimal().toDouble()
var gdaA = gda.toString().toBigDecimal().toDouble()
var goluriDA = (gdaA/ntmA).toString().toDouble()
//Debug Exception.kt:45----> val dgoluriDA:Double = String.format("%.3f", goluriDA).toDouble()
var goluriDAa = dgoluriDA.toString()
intent.putExtra("tvRgda",goluriDAa)
//deplasare date
var gdda = gdd.toString().toBigDecimal().toDouble()
var goluridd = (gdda/ntmA).toString().toDouble()
val dgoluridd:Double = String.format("%.3f", goluridd).toDouble()
var goluridda = dgoluridd.toString()
intent.putExtra("tvgdd",goluridda)


/** Calcularea medie goluri selectie **/
//inscrise acasa gazde
var ntmMA = ntmM.toString().toBigDecimal().toDouble()
var gdaMgA = gdaMG.toString().toBigDecimal().toDouble()
var gdaMgaA: Double = (gdaMgA/ntmMA).toString().toDouble()
var goluriMG = gdaMgaA.toString()
// inscrise deplasare oaspeti
var gdMO = gdaMO.toString().toBigDecimal().toDouble()
var gdMOd = (gdMO/ntmMA).toString().toDouble()
// var gdMOda = gdMOd.toString()
//primite acasa gazda
var gpMGa = gpaMG.toString().toBigDecimal().toDouble()
var gpMGaA = (gpMGa/ntmMA).toString().toDouble()
// var gpMGaAa = gpMGaA.toString()
//primite acasa oaspete
var gpMOa = gpaMO.toString().toBigDecimal().toDouble()
var gpMOaa = (gpMOa/ntmMA).toString().toDouble()
// var gpMOA = gpMOaa.toString()
/** Calculare forta de atac **/
//forta atac gazda
var fortaAG = gdaMgaA/goluriDA
var fortaAO = gdMOd/goluridd
var fortaDG = gpMGaA/goluridd
var fortaDO = gpMOaa/goluriDA
/** Calculare numarului de goluri estimat sa fie inscris **/
// cate goluri ar trebuii sa inscrie gazda
var predGazda = fortaAG*fortaDO*goluriDA
val dpredGazda:Double = String.format("%.3f", predGazda).toDouble()
var gazdaGol = dpredGazda.toString()
intent.putExtra("gazdeG", gazdaGol)
var predOaspeti = fortaAO*fortaDG*goluridd
val dpredOaspeti:Double = String.format("%.3f", predOaspeti).toDouble()
var oaspetiGol= dpredOaspeti.toString()
intent.putExtra("oaspetiG", oaspetiGol)
startActivity(intent)

}
}catch (ex: Exception){
println("Exception $ex")
}

}

}
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
fun fixUpLocale(ctx: Context, newLocale: Locale) {
val res = ctx.resources
val config = res.configuration
val curLocale = getLocale(config)
if (curLocale != newLocale) {
Locale.setDefault(newLocale)
val conf = Configuration(config)
conf.setLocale(newLocale)
res.updateConfiguration(conf, res.displayMetrics);
}
}

fun getLocale(config: Configuration): Locale {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
return config.locales[0]
} else {
//noinspection deprecation
return config.locale;
}

当我在英语语言环境上调试时,一切正常,没有出现错误。
主要事件得到很好的翻译,在应用程序粉碎的第二个事件的意图上
请帮忙,我找不到这个问题的解决方案
 E/AndroidRuntime: [ERB] Update app failure countmain
[ERB] Update app failure - ActivityThread.currentProcessName : com.example.sportbetodds
[ERB] Update app failure - Process.myPid : 10552
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.sportbetodds, PID: 10552
java.lang.NumberFormatException: Invalid double: "1,145"
at java.lang.StringToReal.invalidReal(StringToReal.java:63)
at java.lang.StringToReal.initialParse(StringToReal.java:164)
at java.lang.StringToReal.parseDouble(StringToReal.java:282)
at java.lang.Double.parseDouble(Double.java:301)
at com.example.sportbetodds.MainActivity$onCreate$1.onClick(MainActivity.kt:45)
at android.view.View.performClick(View.java:5205)
at android.view.View$PerformClick.run(View.java:21164)
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)

正如异常所说,我尝试检查异常中指定的输入有什么问题,但一切看起来都很好

最佳答案

看这个

Invalid double: "1,145"

您使用逗号而不是句点在某处定义了 double 。

检查您的翻译。罗马尼亚语和西类牙语变体使用 1,145而不是 1.145

关于当语言环境不是英语时,Kotlin 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54657538/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com