在非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了
posted on 2015-12-15 16:45  超宇  阅读(1162)  评论(0编辑  收藏  举报