Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getResources does not work / undefined Java

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()
    }


}
like image 489
Udo Avatar asked Nov 27 '22 06:11

Udo


1 Answers

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()
}
like image 94
ccheneson Avatar answered Nov 29 '22 19:11

ccheneson