Path: csiph.com!x330-a1.tempe.blueboxinc.net!feeder1.hal-mli.net!feeder.news-service.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Dirk Bruere at NeoPax Newsgroups: comp.lang.java.programmer Subject: Re: Android: create drawable from path Date: Fri, 15 Apr 2011 00:52:52 +0100 Organization: Dirk Bruere at Neopax Lines: 127 Message-ID: <90pfmdF17bU1@mid.individual.net> References: <90opnjFunsU1@mid.individual.net> <908b85be-4c87-4bd6-b5f1-4b82ffeea13e@b13g2000prf.googlegroups.com> <90p3v4Fe4fU1@mid.individual.net> Reply-To: dirk.bruere@gmail.com Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net GK1yxhXFnLt2sfLzE8RRwwmLxqP3yCA8OdQWkpDI9gOatcq79M Cancel-Lock: sha1:hmNNJNUGVbg3ejRXadiHE/S2KbA= User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.15) Gecko/20110303 Thunderbird/3.1.9 In-Reply-To: Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:3066 On 14/04/2011 23:32, Lew wrote: > On 04/14/2011 04:32 PM, Dirk Bruere at NeoPax wrote: >> On 14/04/2011 20:06, Lew wrote: >>> On Apr 14, 1:37 pm, Dirk Bruere at NeoPax >>> wrote: >>>> For some reason d=null when creating a drawable from coverArtURLStr, >>>> which is the full http path to the resource on the LAN. >>>> >>> >>> Are you certain that value is what the method sees? >>> >>>> Anything obvious wrong? It's a path to a .png >>>> [I can access the LAN OK, and Data.defaultCoverArt works fine] >>>> >>>> public static void updateCoverArt(String coverArtURLStr) >>>> { >>>> String coverArtURL = coverArtURLStr; >>>> >>> >>> Why the extra 'String' assignment? >>> >>> What is the *actual* value of 'coverArtURLStr' at this point when you >>> have the problem? >>> >>>> Drawable d; >>>> >>>> if (coverArtURL.equals("")) >>>> d = Data.defaultCoverArt; >>>> else >>>> d = Drawable.createFromPath(coverArtURL); >>>> >>> >>> The value of 'd' at this point when you have the problem is 'null', >>> you say. >>> >>>> Data.coverArtIV.setImageDrawable(d); >>>> } >>>> >>> >>> When you say "I can access the LAN OK", that may or may not bear on >>> whether your program can access the LAN when you're running your >>> test. There's insufficient information in your post for us to know. >>> >>> Since you have not provided an SSCCE there's little likelihood we can >>> debug your problem. On the face of it the'createFromPath()' method is >>> unable to access the actual URL string you're giving it, a datum you >>> have omitted from your problem statement. >>> >>> Provide an SSCCE, please. > >> Actually, there is enough information. > > Now that you've shared it, sure, but not before in the post in which I > pointed out you didn't provide enough information. > >> It seems that >> Drawable.createFromPath(coverArtURL); >> >> doesn't like it if the path is http:\\... > > That information was *not* in your post, so no, there was *not* enough > information in your post. I am happy that we found the correct answer > despite that. It is strange that you're claiming to have provided enough > information by citing data that you did not provide us. Because at the time I did not know it was relevent > Yes, of course it can't parse a URL string of that form. Had you "Of course"? Why is it so obvious? > included that datum in the original post we could have answered with > complete certainty instead of probabilistically (and, as it turned out, > correctly). We'd have seen that you used backslashes in the URL string, > and been able to focus right in on that for you. I do not think that's the problem > At least we were able to focus on the string itself and the likelihood > (now certainty) that it specified an unreachable (or outright invalid) > location, based on the information that was available. > >> I've just got it to work. >> I'll post the code tomorrow for reference > > Thanks. That's a good thing. > public static void updateCoverArt(String coverArtURLStr) { int height=Constants.ART_HEIGHT, width=Constants.ART_WIDTH; Drawable d; ImageView iv = Data.coverArtIV; URL url = null; if (coverArtURLStr.equals("")) { d = Data.defaultCoverArt; } else { try { url = new URL(coverArtURLStr); } catch (MalformedURLException e) {e.printStackTrace();} InputStream content = null; try { content = (InputStream)url.getContent(); } catch (IOException e) {e.printStackTrace();} d = Drawable.createFromStream(content , "src"); } iv.setImageDrawable(d); iv.setAdjustViewBounds(true); iv.setMaxHeight(height); iv.setMinimumHeight(height); iv.setMaxWidth(width); iv.setMinimumWidth(width); } -- Dirk http://www.neopax.com/technomage/ - My new book - Magick and Technology