The method getResources() is undefined for the type
来源:互联网 发布:win to go mac 编辑:程序博客网 时间:2024/05/21 02:51
在非activity的独立类(public class drawThreeD implements Renderer)中调用getResources()时Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.dg);此为调用的语句会出现The method getResources() is undefined for the type
这是因为 getResources() 其实是contex中传递过去的,在非activity类中没有找到可以传递的cavas
解决:将activity类中contex传递过去就好了
1.在activity类中
在创建非activity类时构造函数中添加参数:drawThreeD myRender = new drawThreeD(this.getApplicationContext());
2.在非activity类中
2.1 创建全局变量,用于保存传递过来的context
private Context context;
2.2构造函数中添加参数,并将传递过来的参数赋给全局变量
public drawThreeD(Context context)
{
this.context=context;
}
2.3调用
Bitmap bmp = BitmapFactory.decodeResource(context.getResources(), R.drawable.dg); //这里的context其实是全局变量
- The method getResources() is undefined for the type
- The method getResources() is undefined for the type
- The method getResources() is undefined for the type
- 关于The method getResources() is undefined for the type XX的问题处理
- The method getJspApplicationContext(ServletContext) is undefined for the type JspFactory!
- The method getJspApplicationContext(ServletContext) is undefined for the type JspFactory
- The method getJspApplicationContext(ServletContext) is undefined for the type JspFactory
- The method isEmpty() is undefined for the type String/String
- The method getJspApplicationContext(ServletContext) is undefined for the type
- The method getTextContent() is undefined for the type Node
- The method getTextContent() is undefined for the type Element
- The method getJspApplicationContext(ServletContext) is undefined for the type Js
- The method getTextContent() is undefined for the type Node
- The method setCharacterEncoding(String) is undefined for the type HttpServletResponse
- The method setCharacterEncoding(String) is undefined for the type HttpServletResponse
- The method consume(HttpEntity) is undefined for the type EntityUtils
- 解决The method getCookieStore() is undefined for the type HttpClient
- The method getTextContent() is undefined for the type Node
- codeigniter源代码分析 - 编码类 Utf8.php
- 分布式消息系统Jafka入门指南之二
- jquery原理的简单分析,让你扒开jquery的小外套
- Centos6.5 安装 gcc4.7
- ssh问题:ssh_exchange_identification: Connection closed by remote host...
- The method getResources() is undefined for the type
- 每天学习一点编程(1)(输入一个表示整数的字符串,把该字符串转换成整数并输出)
- 第03讲-自底向上风格_模拟游戏
- Java代码注释 todo XXX fixme 的意义
- 大数相乘
- C/C++程序员:基本排序算法之选择排序
- Oracle pl/sql 出现"PLS-00103: 出现符号""在需要下列之一时" 错误
- Subline Text2 配置python运行环境
- 软件系统的标准化和产品化