Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/187.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android getString不是有效的字符串-安卓-_Android_Android Studio_Getstring - Fatal编程技术网

Android getString不是有效的字符串-安卓-

Android getString不是有效的字符串-安卓-,android,android-studio,getstring,Android,Android Studio,Getstring,我有: (contact是一个字符串变量,也是一个子表单)和: 在这两个地方,getString都启动了一个错误: 格式字符串XXX不是有效的格式字符串,因此不应将其传递给字符串。格式 资源看起来像: new AlertDialog.Builder(NewChatActivity.this).setTitle(getString(R.string.subscriptions)) .setMessage(getString(R.string.

我有:

(contact是一个字符串变量,也是一个子表单)和:

在这两个地方,
getString
都启动了一个错误:

格式字符串XXX不是有效的格式字符串,因此不应将其传递给字符串。格式

资源看起来像:

new AlertDialog.Builder(NewChatActivity.this).setTitle(getString(R.string.subscriptions))
                            .setMessage(getString(R.string.subscription_prompt, subFrom))
                            .setPositiveButton(R.string.approve_subscription, new DialogInterface.OnClickListener() {
                                ....}
邀请已发送到%1$s。

最糟糕的是,该项目当时在Eclipse上,在迁移到AndroidStudio之后,将启动此错误


getString的问题在哪里?

您发布的代码的错误解释是:

<string name="invitation_sent_prompt"> Invitation has been sent to <xliff:g id="user">%1$s</xliff:g>.</string>
你的案子是第一个;现在,在你的链式调用中,我没有看到
字符串.format
调用。试着这样做:

This lint warning checks for two related problems: 
(1) Formatting strings that are invalid, meaning that String.format will 
    throw exceptions at runtime when attempting to use the format string.   
(2) Strings containing '%' that are not formatting strings getting passed
    to a String.format call. In this case the '%' will need to be escaped
    as '%%'.

在您的情况下,
子ROM
需要是一个字符串。此外,请检查所有翻译文件中的格式字符串是否为“%1$s”

我不知道xliff是什么,但我认为在您的情况下,lint检查字符串并看到所有xliff内容,但不知道如何处理它。也许在eclipse设置中,这是先处理的,而在android中,lint会先检查它。不确定,只是我的猜测。@miva2:“字符串通常包含不应翻译为其他语言的文本。常见的示例可能是一段代码、值的占位符、特殊符号或名称。在准备翻译字符串时,查找并标记应保持原样的文本,而不进行翻译,以便翻译人员不会更改它。要标记不应翻译的文本,请使用占位符标记。[示例:“%1$s”]
This lint warning checks for two related problems: 
(1) Formatting strings that are invalid, meaning that String.format will 
    throw exceptions at runtime when attempting to use the format string.   
(2) Strings containing '%' that are not formatting strings getting passed
    to a String.format call. In this case the '%' will need to be escaped
    as '%%'.
new AlertDialog.Builder(NewChatActivity.this).setTitle(getString(R.string.subscriptions))
              .setMessage(String.format(getString(R.string.subscription_prompt, subFrom)))
...