Reputation: 7708
So i have this interface :
public interface Utils{
static final Typeface FONT = Typeface.createFromAsset(getAssets(), "fonts/font.ttf");;
}
I am having an error in getAssets()
, it says The method getAssets() is undefined for the type Utils why is that? Please help thanks :)
Upvotes: 2
Views: 552
Reputation: 83567
Your Utils
class does not have a method named getAssets()
. I assume you want to use the one from the Android Context
class. This means you need to have a Context
object to call getAssets()
. Without more details about your exact app design, I can't help you any further.
One possible solution is to create an Activity
subclass which all of your other activities extend. You also need to honor the activity life-cycle:
public abstract FontActivity extends Activity {
private Typeface font;
@Override
public onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
font = Typeface.createFromAsset(getAssets(), "fonts/font.ttf");
}
}
Now extend FontActivity
instead of Activity
.
Upvotes: 6