Reputation: 119
I have an int variable with 6 elements. All the time in the code android sets it to null. I even redefined it in the code in debug mode like this
if (yeahsort == null) {
SharedPreferences prefs2 = getSharedPreferences("KARANTÄN", MODE_PRIVATE);
String savedString = prefs2.getString("string", null);
StringTokenizer st = new StringTokenizer(savedString, ",");
int[] yeahsort = new int[6];
for (int i = 0; i < 6; i++) {
yeahsort[i] = Integer.parseInt(st.nextToken());
}
}
during the for loop the variable yeahsort
becomes an int[]
, but right after it becomes null
again. Seriously right after the for loop.
So what can I do to fix this?
Upvotes: 0
Views: 436
Reputation: 8277
Instead of int[] yeahsort = new int[6]
change it to yeashsort = new int[6]
here is a lesson on variable scoping http://www.java-made-easy.com/variable-scope.html
Upvotes: 5