【发布时间】:2013-04-25 00:24:43
【问题描述】:
这是我的res/values-es/strings.xml 文件中的一个字符串:
<string name="jcq1">Text text text textttttttttt</string>
这是我在 java 代码中使用它的地方:
jc.add(new Question("42", "21", "33", "29", 0, getResources().getString(R.string.jcq1), -1));
它给了我这个错误:
The method getResources() is undefined for the type Quiz
其中Quiz 是java 代码所在的类的名称。 getResources() 方法的所有其他示例代码似乎都以与我相同的方式使用它,没有问题。什么是我的实现不工作?
编辑
public class Quiz {
public Quiz(Context c) {
jc.add(new Question("42", "21", "33", "29", 0, c.getResources().getString(R.string.jcq1), -1));
// 300 other lines pretty much identical to the one above follows...
【问题讨论】:
-
你能发布测验课程代码吗?我想知道你是否可以使用 context.getResources() 等。
-
编辑开篇文章以包含测验课程代码。
标签: java android resources getresource