gpt4 book ai didi

android - UnknownFormatConversionException : Android strings. xml 格式 <![CDATA[ ...%1$... ]]>

转载 作者:太空狗 更新时间:2023-10-29 16:40:04 27 4
gpt4 key购买 nike

我正在尝试在 strings.xml 中使用格式化的 html。所以在 strings.xml 我有以下内容:

<string name="application_start_message" formatted="false">
<![CDATA[ bla bla bla %1$ bla bla bla %1$.... ]]>
<string name="application_website_url">website.com</string>

然后在我的代码中:

String string = getString(
R.string.application_start_message,
getString(R.string.application_website_url)
);

我得到的运行时异常是:

java.lang.RuntimeException: Unable to start activity 
ComponentInfo{com.artigile.checkmyphone/
com.artigile.checkmyphone.MainActivity}:
java.util.UnknownFormatConversionException: Conversion: <
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)

Caused by: java.util.UnknownFormatConversionException: Conversion: <
at java.util.Formatter$FormatToken.unknownFormatConversionException(Formatter.java:1399)
at java.util.Formatter$FormatToken.checkFlags(Formatter.java:1336)
at java.util.Formatter.transform(Formatter.java:1442)
at java.util.Formatter.doFormat(Formatter.java:1081)
at java.util.Formatter.format(Formatter.java:1042)
at java.util.Formatter.format(Formatter.java:1011)
at java.lang.String.format(String.java:1988)
at android.content.res.Resources.getString(Resources.java:354)
at android.content.Context.getString(Context.java:347)
at com.artigile.checkmyphone.MainActivity.buildModalStartWarningWindow(MainActivity.java:280)
at com.artigile.checkmyphone.MainActivity.onStart(MainActivity.java:116)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1171)
at android.app.Activity.performStart(Activity.java:5143)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
... 11 more

有什么解决方法吗?

最佳答案

我不确定这是否是您问题中的拼写错误,但看起来您没有关闭字符串标记并且您的变量不正确。回车也可能有问题,所以也去掉它。

改变:

<string name="application_start_message" formatted="false">
<![CDATA[ bla bla bla %1$ bla bla bla %1$.... ]]>

<string name="application_start_message" formatted="false"><![CDATA[ bla bla bla %1$s bla bla bla %1$s .... ]]></string>

关于android - UnknownFormatConversionException : Android strings. xml 格式 &lt;![CDATA[ ...%1$... ]]>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19279699/

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