getResources不起作用/未定义的Java [英] getResources does not work / undefined Java

查看:320
本文介绍了getResources不起作用/未定义的Java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有caling的 getResources()函数的标准类的问题。所有的进口必须在那里使用的功能。有没有什么特殊的类,我需要延长我的班?

谢谢你的即时帮助。

 包com.example.helloandroid;

进口android.app.Activity;
进口android.content.ContentValues​​;
进口android.content.Context;
进口android.content.ContextWrapper;

进口android.content.res.Resources;

进口android.content.Intent;
进口android.os.Bundle;

//进口android.content.res.Resources;
进口android.database.Cursor;
进口android.database.SQLException;
进口android.database.sqlite.SQLiteDatabase;
进口android.database.sqlite.SQLiteOpenHelper;
进口android.util.Log;


公共类DbAdapter {

    公共DbAdapter(){
     资源RES = getResources(); //错误:该方法getResources()是未定义的类型DbAdapter
            //还tyed context.getResources()
    }


}
 

解决方案

getResouces 是的Context 。 所以,你可以通过上下文的DbAdapter构造和呼叫 getResources 从它:

 公共DbAdapter(上下文的背景下){
     资源RES = context.getResources(); //错误:该方法getResources()是未定义的类型DbAdapter
            //也追平context.getResources()
}
 

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

这篇关于getResources不起作用/未定义的Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆