java - getResources 不起作用/未定义 Java

标签 java android undefined

我在调用标准类中的 getResources() 函数时遇到问题。所有导入都必须在那里才能使用该功能。我需要延长类(class)的特殊类(class)吗?

感谢您的及时帮助。

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


}

最佳答案

getResoucesContext 的一个方法. 因此,您可以将上下文传递给 DbAdapter 构造函数并从中调用 getResources :

public DbAdapter(Context context) {
     Resources res = context.getResources();//error: The method getResources() is undefined for the type DbAdapter
            //also tied context.getResources()
}

关于java - getResources 不起作用/未定义 Java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4338400/

相关文章:

java - Android 中的时间计算

android - 从 Application 对象中获取网络请求的好方法?

javascript - 什么时候在 JavaScript 中使用 null 或 undefined?

java - 算法AES和算法Twofish

java - 如何使用 if 语句来更改属性的值?

java - 更改 JComboBox 箭头按钮的图标

java - 在android中后台访问麦克风

java - 需要 android 计时器秒数重置为 60

javascript - "TypeError: undefined is not a function"

python - 应该定义 undefined variable ,但我把它弄得太复杂了