getResources from custom class

Put your problem here if it does not fit any of the other categories.

getResources from custom class

Postby lesmond » Sun Jul 04, 2010 6:07 pm

Hello,

I have a custom class that creates OverlayItems and puts them into an array. It will do this away from the main thread.

I try and use

Code: Select all
Drawable test = getResources().getDrawable(R.drawable.icon);


But get the following error....

The method getResources() is undefined for the type XMLHandler
lesmond
Junior Developer
Junior Developer
 
Posts: 11
Joined: Thu Jul 01, 2010 7:26 am

Top

Re: getResources from custom class

Postby blundell » Sun Jul 04, 2010 9:58 pm

Your class doesn't extend Activity so you can't call getResources()
User avatar
blundell
Master Developer
Master Developer
 
Posts: 1610
Joined: Tue Nov 18, 2008 12:58 pm
Location: UK

Re: getResources from custom class

Postby padde » Sun Jul 04, 2010 10:12 pm

Just make the Context of your activity static so you have access.. or pass the Context to your custom class
via constructor etc.

This must be the 234987982020340987100234. time a similar question like this was answered.. congratulations
you won the Lazy-User-WTH-is-a-search-function award!
padde
Master Developer
Master Developer
 
Posts: 443
Joined: Wed Apr 08, 2009 4:52 pm

Re: getResources from custom class

Postby lesmond » Mon Jul 05, 2010 6:05 am

Thanks for the friendly reply
lesmond
Junior Developer
Junior Developer
 
Posts: 11
Joined: Thu Jul 01, 2010 7:26 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Yahoo [Bot] and 16 guests