The method getResources() is undefined for the type

在非activity的独立类(public class readwhatsapp)中调用getResources()时(InputStream is = getResources().openRawResource(R.raw.wa_contacts.db)),出现The method getResources() is undefined for the type

这是因为 getResources() 其实是contex中传递过去的,在非activity类中没有找到可以传递的cavas

解决:将activity类中contex传递过去就好了

创建全局变量,用于保存传递过来的context

          private Context context;

调用InputStream is = context.getResources().openRawResource(R.raw.wa_contacts.db);就OK了

时间: 2024-10-31 13:30:16

The method getResources() is undefined for the type的相关文章

The method getconn() is undefined for the type words

问题描述 为什么我明明定义了方法,还回出现错误??包contorl下有两个类,一个accessdb类,一个words类继承accessdb:而在jsp调用words这个javabean但是出现我没定义方法为什么???accessdb源代码:packagecontrol;importjava.sql.*;publicclassaccessdb{Connectioncon;Statementstmt;ResultSetrs;publicvoidaccessdb(){stmt=null;rs=null

The method getSingleResult() is undefined for the type Query

问题描述 关联的代码提取下 QueryResult qr = new QueryResult<T>(); Query query = this.getSession().createQuery("select count(o) from "+entityName+" o " +(wherejpql==null? "": " where "+ wherejpql)); qr.setTotalRecord(query.

The method getTextContent() is undefined for the type Node ?

问题描述 Jdk改成1.6和1.7都没用 解决方案 解决方案二:基本类型long不能为空,用对象类型应该没有问题Long.Integer解决方案三:基本类型long不能为空,用对象类型应该没有问题Long.Integer解决方案四:回错地方了

java sting split- The method sqlit(String) is undefined for the type String

问题描述 The method sqlit(String) is undefined for the type String 小弟新手!!!split()函数以前用的好好地!今天突然直接就报个这么个错误!!看了半天没发现错误!用法跟以前一模一样啊!为什么会报错呢!!导致jsp页面无法编译!传递参数为:&steelmar=YT201%20,%20Ф5.5-Ф20 报错代码String[] ms = electty.sqlit(",");!!!!求高人指点迷津啊!!!!!!!!!!

The method getParmaeter(String) is undefined for the type HttpServletRequest

问题描述 <%@ page pageEncoding="gb2312"%><%@ page contentType="text/html; charset=gb2312" language="java" %><% request.setCharacterEncoding("gb2312");%><%@ page import="java.sql.*" errorPa

imageview-如何访问一个 activity 以外的资源?

问题描述 如何访问一个 activity 以外的资源? 我有下面的代码: Bitmap bMap = BitmapFactory.decodeResource(getResources(), R.drawable.icon); imageView.setImageBitmap(bMap); 但是获得以下的错误: The method getResources() is undefined for the type ImageDownloader 如何访问资源呢? 解决方案 在你的 ImageDo

ajax-highcharts---XXX.xAxis is undefined求解!!!

问题描述 highcharts---XXX.xAxis is undefined求解!!! 控制台提示错误:XXX.xAxis is undefined 图1 highcharts的初始化) ajax获取图标中数据的方法 控制台提示错误:XXX.xAxis is undefined 解决方案 你的tar_chart实例化过没有,而且xAxis是数组,没有setCatalogories方法 http://www.hcharts.cn/api/index.php#Chart.xAxis 解决方案二:

arrayadapter-The constructor ArrayAdapter&amp;amp;lt;String&amp;amp;gt;is undefined

问题描述 The constructor ArrayAdapter<String>is undefined The constructor ArrayAdapter(XListViewActivity, int, ArrayList) is undefined,向各位大神求解 解决方案 Android错误:方法setListAdapter(ArrayAdapter) is undefined for the type Stringhe method isEmpty() is undefined

notification-Android开发关于通知的build()方法的问题

问题描述 Android开发关于通知的build()方法的问题 Bitmap btm = BitmapFactory.decodeResource(getResources(), R.drawable.mouse); Notification.Builder mBuilder = new Notification.Builder( MsgService.this).setSmallIcon(R.drawable.mouse) .setContentTitle("1 new message&quo