简体   繁体   English

R.string无法解析或不是字段

[英]R.string cannot be resolved or is not a field

I am programming a map in android, I follow this tutorial hier ,and I want to add error messages, but the errors are not in R class. 我正在用android编程地图,我遵循了本教程的更高层次 ,我想添加错误消息,但是错误不在R类中。 The errors, which I mean, are: R.string.invalid_lat_long_used, R.string.service_not_available R.string.no_address_found, R.string.address_found 我的意思是,错误是:R.string.invalid_lat_long_used,R.string.service_not_available R.string.no_address_found,R.string.address_found
how can I resolve this problem? 我该如何解决这个问题?

The link that you followed, doesnt says about the changes that you have to make in other resource files. 您所遵循的链接没有说明您必须在其他资源文件中进行的更改。

The reason why you are not able to get R.string.invalid_lat_long_used , R.string.service_not_available etc are because, these are custom strings that are specified by you. 之所以无法获得R.string.invalid_lat_long_usedR.string.service_not_available等,是因为这些是您指定的自定义字符串。 So you'll have to declare these strings in a file named Strings.xml manually. 因此,您必须手动在名为Strings.xml的文件中声明这些字符串。

You can see that, there is already a file named Strings.xml in your project. 您会看到,项目中已经有一个名为Strings.xml的文件。 So you'll have to edit the Strings.xml file with all the above mentioned Strings. 因此,您必须使用上述所有Strings编辑Strings.xml文件。

According to the docs , values in Strings.xml can be set as follows 根据文档 ,可以如下设置Strings.xml

<resources>
    <string name="test_text">Test</string>
    <string name="clear_text">Clear</string>
    <string name="wifi_connection">The active connection is wifi.</string>
    <string name="mobile_connection">The active connection is mobile.</string>
    <string name="no_wifi_or_mobile">No wireless or mobile connection.</string>
</resources>

So for your case the Strings.xml file should contain all these Strings too 因此对于您的情况, Strings.xml文件也应包含所有这些字符串

<string name="invalid_lat_long_used">Invalid Lat Long</string>
<string name="service_not_available ">Service Not Available</string>
<string name="no_address_found">No address found</string>
<string name="address_found">Address found</string>

etc.. 等等..

Strings.xml file can be found inside res / values / 可以在res / values /找到Strings.xml文件

Add that values inside the Strings.xml file: 将这些值添加到Strings.xml文件中:

<string name="invalid_lat_long_used">Invalid Lat Long Used</string>
<string name="service_not_available ">Service Not Available</string>
<string name="no_address_found">No Address Found</string>
<string name="address_found">Address Found</string>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM