I am trying to use an array of objects but when I use the array in other methods within the same class, the array comes up null.
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);
}
When I check the summonArray[1] in my onCreate method, it has all the values I want, but when I look at it in the onClick or other methods the debugger shows the value as null.
break;
Your re-declaring your array.
The global one is not used, change your onCreate to do this: