Java 错误:(64,72)错误:非静态方法getString(int)
怎么了? 我正在尝试提取strings.xml中使用的字符串 但我得到了一个错误:Java 错误:(64,72)错误:非静态方法getString(int),java,android,Java,Android,怎么了? 我正在尝试提取strings.xml中使用的字符串 但我得到了一个错误: Error:(64, 72) error: non-static method getString(int) cannot be referenced from a static context 代码: 创建扩展应用程序的类MyApplication。实现单例: private static MyApplication instance; public static MyApplication getInst
Error:(64, 72) error: non-static method getString(int) cannot be referenced from a static context
代码:
创建扩展应用程序的类MyApplication。实现单例:
private static MyApplication instance;
public static MyApplication getInstance() {
return instance;
}
public void onCreate() {
instance = this;
}
然后使用MyApplication.getInstance().getString(R.string.next\u update\u id)
希望对你有帮助 创建扩展应用程序的类MyApplication。实现单例:
private static MyApplication instance;
public static MyApplication getInstance() {
return instance;
}
public void onCreate() {
instance = this;
}
然后使用MyApplication.getInstance().getString(R.string.next\u update\u id)
希望对你有帮助 您收到的消息已经是答案:是一个非静态方法,您正在尝试在静态上下文中使用它。这里的“静态上下文”是指定义静态变量
private static String file_url
您可以通过从成员声明中删除静态修饰符来解决此问题。您收到的消息已经是答案:是一个非静态方法,您正在尝试在静态上下文中使用它。这里的“静态上下文”是指定义静态变量
private static String file_url
您可以通过从成员声明中删除静态修饰符来解决此问题。简单修复
private static String file_url;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Add only this
file_url = "http://xxxx.yy/" + getString(R.string.next_update_id);
}
简单修复
private static String file_url;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Add only this
file_url = "http://xxxx.yy/" + getString(R.string.next_update_id);
}
你的“getString”方法在哪里?xxxxx来自strings.xmlops,忘了它是Android。没问题,谢谢你的“getString”方法在哪里的时间可能重复?xxxxx来自strings.xmlops,忘了它是Android。没问题,再次感谢你的时间可能重复的错误。错误:无法再次从静态contextError引用非静态方法getResources(int)。错误:无法从静态方法引用非静态方法getResources(int)context@cricket_007当前接受的答案没有错。我把它延长了。加上如何简单地修复它。@cricket_007对当前接受的答案没有错误。我把它延长了。加上如何简单地修复它。