Issue
In an IntentService class i want to put some Arrays from Android xml files in an ArrayList, Android-Studio doesnt accept this, but only if i want to add it in an ArrayList. Android Studio says it found a Boolean instead a String[]. But why Boolean? this are String[]. In another Code-Fragment, i can work with this String[] that i get from getResources() without a problem.
private ArrayList<String[]> alleTermine = new ArrayList<String[]>();
private String[] hausmuell;
private String[] gelbeSaecke;
private String[] gruenAbfall;
private String[] altPapier;
public void onCreate() {
super.onCreate();
Resources res = getResources();
//this makes a String[]
hausmuell = res.getStringArray(R.array.hausmuell);
gelbeSaecke = res.getStringArray(R.array.gelber_sack);
gruenAbfall = res.getStringArray(R.array.gruenabfall);
altPapier = res.getStringArray(R.array.altpapier);
alleTermine=alleTermine.add(hausmuell)
}
The xml.file looks like this:
<?xml version='1.0' encoding='utf-8'?>
<resources>
<string-array name='hausmuell'>
<item>1482451200000</item>
<item>1452214800000</item>
<item>1453424400000</item>
<item>1454634000000</item>
<item>1455843600000</item>
</string-array>
</resources>
Solution
alleTermine=alleTermine.add(hausmuell)
ArrayList#add()
method returns a boolean, and you're trying to assign the return value to an ArrayList
. That won't compile.
You probably want something like:
alleTermine = new ArrayList<>();
alleTermine.add(hausmuell);
Answered By - laalto
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.