安卓则getIdentifier不适用于字符串工作吗? [英] Android getIdentifier doesn't work for string?

查看:159
本文介绍了安卓则getIdentifier不适用于字符串工作吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的不知道为什么,但我无法检索到字符串的ID。

这是我的code:

  INT渣油= getApplicationContext()。getResources()
           .getIdentifier(About_EmailPrompt,串,com.yoki.android.cat);
 

但它完全适用于所有其他类R档的:

  INT渣油= getApplicationContext()。getResources()
           .getIdentifier(箭头,绘制,com.yoki.android.cat);
 

所以,我真的不明白是怎么回事,什么想法?

解决方案

这code貌似正确的code:

  INT渣油= getApplicationContext()getResources()则getIdentifier(About_EmailPrompt,串,com.yoki.android.cat)。
 

和它应该工作,但是如果不是我劝你不要试图来解决这个问题,并试图理解为什么这是行不通的:

1)首先试图找到在你的项目/项目旁边declarated领域:

  About_EmailPrompt
 

如果您使用的是您精选文摘要preSS的按Ctrl + H 的和开放的的Java搜索的标签

如果你去搜索得到的结果第2步,否则转到第3步

2)你应该得到的结果如下层次

 < YOUR_PACKAGE_NAME>
     -  R的
      -  串
          -  About_EmailPrompt
 

2.1)检查您在code编写正确的包名

  .getIdentifier(About_EmailPrompt,串,< YOUR_PACKAGE_NAME>);
 

2.2)检查您在文字字符串只使用拉丁字符:

 About_EmailPrompt
 

 字符串
 

2.3)检查在名称属性,的strings.xml

仅使用拉丁字符

 <字符串名称=About_EmailPrompt> SOME_VALUE< /串>
 

3)如果您没有搜索结果

3.1)检查你在文本字符串只使用拉丁字符:

 About_EmailPrompt
 

3.2)检查在名称属性,的strings.xml

仅使用拉丁字符

 <字符串名称=About_EmailPrompt> SOME_VALUE< /串>
 

3.3)做清洁,构建你把所有的项目

P.S。如果不帮你,请尝试重新启动您的IDE(有时日食产生R.java错误,直到重新启动)

I really don't know why but I can't retrieve the Id of a String.

This is my code:

int resId = getApplicationContext().getResources()
           .getIdentifier("About_EmailPrompt", "string", "com.yoki.android.cat");

But it works perfectly for all other classes of R file:

int resId = getApplicationContext().getResources()
           .getIdentifier("arrow","drawable", "com.yoki.android.cat");

So I really don't understand what's going on here, any ideas ?

解决方案

This code looks like correct code:

int resId = getApplicationContext().getResources().getIdentifier("About_EmailPrompt", "string", "com.yoki.android.cat");

and it should work, but if not I advise you do not try to get around this and try to understand Why it doesn't work:

1) First of all try to find next declarated field in your project/projects:

About_EmailPrompt

if you are using eclips you should press Ctrl+H and open Java Search tab

If you get results for searching go to step 2 otherwise go to step 3

2) You should get result as hierarchy

<YOUR_PACKAGE_NAME>
    -- R
     -- string
         -- About_EmailPrompt

2.1) check you write correct package name in your code

.getIdentifier("About_EmailPrompt", "string", <YOUR_PACKAGE_NAME>);

2.2) check you use just latin symbols in your literal strings:

"About_EmailPrompt"

and

"string"

2.3) check you use just latin symbols in name attribute in strings.xml

<string name="About_EmailPrompt">SOME_VALUE</string>

3) If you have no search result

3.1) check you use just latin symbols in your literal string:

"About_EmailPrompt"

3.2) check you use just latin symbols in name attribute in strings.xml

<string name="About_EmailPrompt">SOME_VALUE</string>

3.3) Do clean and build for all projects you have

P.S. If this does not help you, try to restart your IDE (sometimes eclipse generate R.java incorrectly until restarting)

这篇关于安卓则getIdentifier不适用于字符串工作吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆