I know that we cannot call a method from an Activity that is in another action. I am trying to find a better way around this.
Here is my code. This is the method I'm trying to call. He is in my activity ScoreCard.
public void numPlayerSetup(){
{
int[] ids = {
R.id.TextView11, R.id.TextView12, R.id.TextView13
};
for(int i : ids) {
TextView tv = (TextView)findViewById(i);
tv.setVisibility(View.INVISIBLE);
}
}
This is how I try to call the method. scoreis an object of a class ScoreCard.
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3){
int item = spinner.getSelectedItemPosition();
if(item==1){
Log.i("error","This Sucks");
score.numPlayerSetup();
}
}
I tried to put the method numPlayerSetupin another class that would not extend Activity, it would just contain logic, but I can not use the method findViewById()without the extension of activity.
This is what I call him.
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3){
int item = spinner.getSelectedItemPosition();
ArrayList<TextView> myTextViewList = new ArrayList<TextView>();
TextView tv1 = (TextView)findViewById(R.id.TextView14);
myTextViewList.add(tv1);
if(item==1){
Log.i("error","This Sucks");
Setup.numPlayerSetup(myTextViewList);
}
Then this is the class I'm calling.
public class Setup {
TextView tv;
public static void numPlayerSetup(ArrayList<TextView> tvs){
for(TextView tv : tvs) {
Log.i("crash","This Sucks");
tv.setVisibility(View.INVISIBLE);
}
}
}
It logs the message in logcat and gives me a null pointer exception. The debugger says that the value for tv is null. So I get a null pointer exception?
user631063