use*_*266 0 variables null android exception
我有一个带有6个元素的int变量.代码中的所有时间都将android设置为null.我甚至在调试模式的代码中重新定义了它
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());
}
}
Run Code Online (Sandbox Code Playgroud)
在for循环期间,变量yeahsort变为a int[],但在变为a null之后.在for循环之后认真对待.
那么我该怎么做才能解决这个问题呢?
而不是int[] yeahsort = new int[6]将其改为yeashsort = new int[6]这里是关于变量范围的教训http://www.java-made-easy.com/variable-scope.html