Issue
I'm using robolectric framework to test my android project. It is working very well but i couldn't find how to solve the problem:
In my activity class, i have to take the current language as follows:
private void setCurrentLanguageChoosenInRadioGroup() {
Configuration c = new Configuration(getResources().getConfiguration());
String locale = c.locale.getLanguage();
if(locale.equalsIgnoreCase(Constants.DUTCH_LANGUAGE)){
radioLanguageGroup.check(dutchButton.getId());
}
else if(locale.equalsIgnoreCase(Locale.FRENCH.getLanguage())){
radioLanguageGroup.check(frenchButton.getId());
}
else if(locale.equalsIgnoreCase(Locale.ENGLISH.getLanguage())){
radioLanguageGroup.check(englishButton.getId());
}
}
But in the line of "c.locale.getLanguage();" i get nullpointerexception. It is my testing method:
public void setUp() throws Exception {
activity = new MainActivity();
activity.onCreate(null); ....
Has anybody a idea what is the problem and how can it be solved?
Solution
Updating robolectric to versions 2.x resolves the problem! In versions 0.9.x which is default version on their website, it is not applicable!
Thus, it can be adapted in this way:
Locale loc = new Locale("desired language/country");
Configuration c = new Configuration();
c.setLocale(loc);
Answered By - Asqan
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.