0

I'm relatively new to Java and I'm trying to create a dataHandler for an xml. But I get an error: "The method getResources() is undefined for the type CasusHandler".

What am I forgetting?

import android.content.res.Resources;

public class CasusHandler {

    public String[] casus;

    public void setCasusArray() {
        Resources res = getResources();
        this.casus = res.getStringArray(R.array.casus);
    }

    public String[] getCasusArray() {
        return this.casus;
    }

}
Sandeep R
  • 2,284
  • 3
  • 25
  • 51
Sephen
  • 1,111
  • 3
  • 16
  • 38

2 Answers2

1

getResources() is a method of Context. and here you can pass the Context reference to the method setCasusArray()

public void setCasusArray(Context context) {
   this.casus = context.getResources().getStringArray(R.array.casus);
}
Gopal Gopi
  • 11,101
  • 1
  • 30
  • 43
0

you need to pass the Context to you class so you could call getResurces

what you should do is the following :

public class CasusHandler {

    public String[] casus;


    public void setCasusArray(Context context ) {
        Resources res = context.getResources();
        this.casus = res.getStringArray(R.array.casus);
    }

    public String[] getCasusArray() {
        return this.casus;
    }

}

Hope that helps