我想要使用一個對象數組,但是當我在同一個類中的其他方法中使用該數組時,數組變爲空。android在其他方法中使用的數組,但爲空
Summon[] summonArray;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.summonsmenu);
Summon[] summonArray = new Summon[3]; // initialize array
for (int i = 0; i < summonArray.length; i++)
summonArray[i] = new Summon(); // initialize each object in the array
}
public void onClick(View view) {
//@SuppressWarnings("unchecked")
switch (view.getId()) {
case R.id.summonButton1:
name.setText(summonArray[1].getName());
//* this is where I get the null pointer and see that the summonArray[1] is null.*
refresh(summonArray);
}
當我檢查summonArray [1]在我的onCreate方法,它擁有所有我想要的值,但是當我看着它在onclick或其他方法調試器顯示了一個空值。 休息;