다른 클래스에서 호출하려는 정보가 들어있는 간단한 클래스에 문제가 있습니다.확장 활동이없는 호출에서 getstring()
Util u = new Util();
ArrayList<RecetaBean> Recetas = u.getRellenas();
그래서, 나는 클래스 Util
와의 실행에 문제가 :
public class Util{
public ArrayList<RecetaBean> getRellenas() {
ArrayList<RecetaBean> MiLista = new ArrayList<RecetaBean>();
RecetaBean receta1 = new RecetaBean();
String ingrediente1[] = { getString(R.string.app_name),getString(R.string.app_name),
};
receta1.setIngredientesLista(ingrediente1);
MiLista.add(receta1);
MiLista.add(receta1);
MiLista.add(receta1);
return MiLista;
}
}
그런 다음 다른 클래스에서 나는 항목은 다음과 같이 호출 얻을 예를 들어 여기에 정보를 포함하는 클래스 Util
입니다 GETSTRING
, 왜냐하면 나는 다른 문자열 때문에 (다른 언어 때문에) 얻고 싶기 때문이다. 오류를 종료하는 방법은 Util
을 Activity
에서 연장하지만 Util
은 Activity
이 아닙니다! 그리고 Activity
에서 확장하면 앱이 다운됩니다.
''Util'' 생성자 나 Activity에 대한 참조를 전달하거나,보다 정확하게하기 위해''Context''를 전달하십시오. ''Context''에서''getString'' 메서드와 지역화 된 문자열에 접근 할 수 있습니다. – harism