I have a problem with caling the getResources()
function in an standard class. All imports must be there to use the function. Is there any special class I need to extend my class?
Thanks for the immediate help.
package com.example.helloandroid;
import android.app.Activity;
import android.content.ContentValues;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.res.Resources;
import android.content.Intent;
import android.os.Bundle;
//import android.content.res.Resources;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
public class DbAdapter {
public DbAdapter() {
Resources res = getResources();//error: The method getResources() is undefined for the type DbAdapter
//also tyed context.getResources()
}
}
getResouces
is a method of a Context.
So you can pass the context to your DbAdapter constructor and call getResources
from it :
public DbAdapter(Context context) {
Resources res = context.getResources();//error: The method getResources() is undefined for the type DbAdapter
//also tied context.getResources()
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With