Flo07 Posté(e) 5 mai 2010 Share Posté(e) 5 mai 2010 (modifié) Bonjour à tous, Je souhaite télécharger une image d'internet afin de la placer dans un ImageView. J'ai donc le code : public static Bitmap telechargerImage(String url){ Bitmap bm = null; try{ URL aURL = new URL(url); URLConnection conn = aURL.openConnection(); conn.connect(); InputStream is = conn.getInputStream(); BufferedInputStream bis = new BufferedInputStream(is); bm = BitmapFactory.decodeStream(bis); bis.close(); is.close(); Log.e("dl","OK"); } catch(IOException e){ Log.e("Erreur","Erreur IO"); } return bm; } Qui est appelé dans le onCreate par : ((ImageView)findViewById(R.id.Imagedlduweb)).setImageBitmap(telechargerImage("http://www.google.fr/intl/fr_fr/images/logo.gif")); et j'ai les warning suivant : 05-05 13:46:17.071: WARN/ResourceType(1465): No package identifier when getting value for resource number 0x00000001 05-05 13:46:17.102: WARN/ImageView(1465): Unable to find resource: 1 05-05 13:46:17.102: WARN/ImageView(1465): android.content.res.Resources$NotFoundException: Resource ID #0x1 05-05 13:46:17.102: WARN/ImageView(1465): at android.content.res.Resources.getValue(Resources.java:896) 05-05 13:46:17.102: WARN/ImageView(1465): at android.content.res.Resources.getDrawable(Resources.java:584) 05-05 13:46:17.102: WARN/ImageView(1465): at android.widget.ImageView.resolveUri(ImageView.java:485) 05-05 13:46:17.102: WARN/ImageView(1465): at android.widget.ImageView.setImageResource(ImageView.java:270) 05-05 13:46:17.102: WARN/ImageView(1465): at com.LocProMobile.android.Catalog$ImageAdapter.getView(Catalog.java:180) 05-05 13:46:17.102: WARN/ImageView(1465): at android.widget.AbsSpinner.onMeasure(AbsSpinner.java:198) 05-05 13:46:17.102: WARN/ImageView(1465): at android.view.View.measure(View.java:7703) 05-05 13:46:17.102: WARN/ImageView(1465): at android.view.ViewGroup.measureChild(ViewGroup.java:2960) 05-05 13:46:17.102: WARN/ImageView(1465): at android.view.ViewGroup.measureChildren(ViewGroup.java:2937) 05-05 13:46:17.102: WARN/ImageView(1465): at android.widget.AbsoluteLayout.onMeasure(AbsoluteLayout.java:63) 05-05 13:46:17.102: WARN/ImageView(1465): at android.view.View.measure(View.java:7703) 05-05 13:46:17.102: WARN/ImageView(1465): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:2989) 05-05 13:46:17.102: WARN/ImageView(1465): at android.widget.FrameLayout.onMeasure(FrameLayout.java:245) 05-05 13:46:17.102: WARN/ImageView(1465): at android.view.View.measure(View.java:7703) 05-05 13:46:17.102: WARN/ImageView(1465): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:2989) 05-05 13:46:17.102: WARN/ImageView(1465): at android.widget.FrameLayout.onMeasure(FrameLayout.java:245) 05-05 13:46:17.102: WARN/ImageView(1465): at android.view.View.measure(View.java:7703) 05-05 13:46:17.102: WARN/ImageView(1465): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:2989) 05-05 13:46:17.102: WARN/ImageView(1465): at android.widget.FrameLayout.onMeasure(FrameLayout.java:245) 05-05 13:46:17.102: WARN/ImageView(1465): at android.view.View.measure(View.java:7703) 05-05 13:46:17.102: WARN/ImageView(1465): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:2989) 05-05 13:46:17.102: WARN/ImageView(1465): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:888) 05-05 13:46:17.102: WARN/ImageView(1465): at android.widget.LinearLayout.measureVertical(LinearLayout.java:350) 05-05 13:46:17.102: WARN/ImageView(1465): at android.widget.LinearLayout.onMeasure(LinearLayout.java:278) 05-05 13:46:17.102: WARN/ImageView(1465): at android.view.View.measure(View.java:7703) 05-05 13:46:17.102: WARN/ImageView(1465): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:2989) 05-05 13:46:17.102: WARN/ImageView(1465): at android.widget.FrameLayout.onMeasure(FrameLayout.java:245) 05-05 13:46:17.102: WARN/ImageView(1465): at android.view.View.measure(View.java:7703) 05-05 13:46:17.102: WARN/ImageView(1465): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:2989) 05-05 13:46:17.102: WARN/ImageView(1465): at android.widget.FrameLayout.onMeasure(FrameLayout.java:245) 05-05 13:46:17.102: WARN/ImageView(1465): at android.view.View.measure(View.java:7703) 05-05 13:46:17.102: WARN/ImageView(1465): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:2989) 05-05 13:46:17.102: WARN/ImageView(1465): at android.widget.FrameLayout.onMeasure(FrameLayout.java:245) 05-05 13:46:17.102: WARN/ImageView(1465): at android.view.View.measure(View.java:7703) 05-05 13:46:17.102: WARN/ImageView(1465): at android.view.ViewRoot.performTraversals(ViewRoot.java:747) 05-05 13:46:17.102: WARN/ImageView(1465): at android.view.ViewRoot.handleMessage(ViewRoot.java:1613) 05-05 13:46:17.102: WARN/ImageView(1465): at android.os.Handler.dispatchMessage(Handler.java:99) 05-05 13:46:17.102: WARN/ImageView(1465): at android.os.Looper.loop(Looper.java:123) 05-05 13:46:17.102: WARN/ImageView(1465): at android.app.ActivityThread.main(ActivityThread.java:4203) 05-05 13:46:17.102: WARN/ImageView(1465): at java.lang.reflect.Method.invokeNative(Native Method) 05-05 13:46:17.102: WARN/ImageView(1465): at java.lang.reflect.Method.invoke(Method.java:521) 05-05 13:46:17.102: WARN/ImageView(1465): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791) 05-05 13:46:17.102: WARN/ImageView(1465): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549) 05-05 13:46:17.102: WARN/ImageView(1465): at dalvik.system.NativeStart.main(Native Method) 05-05 13:46:17.102: WARN/ResourceType(1465): No package identifier when getting value for resource number 0x00000001 05-05 13:46:17.132: WARN/ImageView(1465): Unable to find resource: 1 05-05 13:46:17.132: WARN/ImageView(1465): android.content.res.Resources$NotFoundException: Resource ID #0x1 05-05 13:46:17.132: WARN/ImageView(1465): at android.content.res.Resources.getValue(Resources.java:896) 05-05 13:46:17.132: WARN/ImageView(1465): at android.content.res.Resources.getDrawable(Resources.java:584) 05-05 13:46:17.132: WARN/ImageView(1465): at android.widget.ImageView.resolveUri(ImageView.java:485) 05-05 13:46:17.132: WARN/ImageView(1465): at android.widget.ImageView.onMeasure(ImageView.java:577) 05-05 13:46:17.132: WARN/ImageView(1465): at android.view.View.measure(View.java:7703) 05-05 13:46:17.132: WARN/ImageView(1465): at android.view.ViewGroup.measureChild(ViewGroup.java:2960) 05-05 13:46:17.132: WARN/ImageView(1465): at android.widget.AbsSpinner.onMeasure(AbsSpinner.java:212) 05-05 13:46:17.132: WARN/ImageView(1465): at android.view.View.measure(View.java:7703) 05-05 13:46:17.132: WARN/ImageView(1465): at android.view.ViewGroup.measureChild(ViewGroup.java:2960) 05-05 13:46:17.132: WARN/ImageView(1465): at android.view.ViewGroup.measureChildren(ViewGroup.java:2937) 05-05 13:46:17.132: WARN/ImageView(1465): at android.widget.AbsoluteLayout.onMeasure(AbsoluteLayout.java:63) 05-05 13:46:17.132: WARN/ImageView(1465): at android.view.View.measure(View.java:7703) 05-05 13:46:17.132: WARN/ImageView(1465): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:2989) 05-05 13:46:17.132: WARN/ImageView(1465): at android.widget.FrameLayout.onMeasure(FrameLayout.java:245) 05-05 13:46:17.132: WARN/ImageView(1465): at android.view.View.measure(View.java:7703) 05-05 13:46:17.132: WARN/ImageView(1465): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:2989) 05-05 13:46:17.132: WARN/ImageView(1465): at android.widget.FrameLayout.onMeasure(FrameLayout.java:245) 05-05 13:46:17.132: WARN/ImageView(1465): at android.view.View.measure(View.java:7703) 05-05 13:46:17.132: WARN/ImageView(1465): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:2989) 05-05 13:46:17.132: WARN/ImageView(1465): at android.widget.FrameLayout.onMeasure(FrameLayout.java:245) 05-05 13:46:17.132: WARN/ImageView(1465): at android.view.View.measure(View.java:7703) 05-05 13:46:17.132: WARN/ImageView(1465): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:2989) 05-05 13:46:17.132: WARN/ImageView(1465): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:888) 05-05 13:46:17.132: WARN/ImageView(1465): at android.widget.LinearLayout.measureVertical(LinearLayout.java:350) 05-05 13:46:17.132: WARN/ImageView(1465): at android.widget.LinearLayout.onMeasure(LinearLayout.java:278) 05-05 13:46:17.132: WARN/ImageView(1465): at android.view.View.measure(View.java:7703) 05-05 13:46:17.132: WARN/ImageView(1465): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:2989) 05-05 13:46:17.132: WARN/ImageView(1465): at android.widget.FrameLayout.onMeasure(FrameLayout.java:245) 05-05 13:46:17.132: WARN/ImageView(1465): at android.view.View.measure(View.java:7703) 05-05 13:46:17.132: WARN/ImageView(1465): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:2989) 05-05 13:46:17.132: WARN/ImageView(1465): at android.widget.FrameLayout.onMeasure(FrameLayout.java:245) 05-05 13:46:17.132: WARN/ImageView(1465): at android.view.View.measure(View.java:7703) 05-05 13:46:17.132: WARN/ImageView(1465): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:2989) 05-05 13:46:17.132: WARN/ImageView(1465): at android.widget.FrameLayout.onMeasure(FrameLayout.java:245) 05-05 13:46:17.132: WARN/ImageView(1465): at android.view.View.measure(View.java:7703) 05-05 13:46:17.132: WARN/ImageView(1465): at android.view.ViewRoot.performTraversals(ViewRoot.java:747) 05-05 13:46:17.132: WARN/ImageView(1465): at android.view.ViewRoot.handleMessage(ViewRoot.java:1613) 05-05 13:46:17.132: WARN/ImageView(1465): at android.os.Handler.dispatchMessage(Handler.java:99) 05-05 13:46:17.132: WARN/ImageView(1465): at android.os.Looper.loop(Looper.java:123) 05-05 13:46:17.132: WARN/ImageView(1465): at android.app.ActivityThread.main(ActivityThread.java:4203) 05-05 13:46:17.132: WARN/ImageView(1465): at java.lang.reflect.Method.invokeNative(Native Method) 05-05 13:46:17.132: WARN/ImageView(1465): at java.lang.reflect.Method.invoke(Method.java:521) 05-05 13:46:17.132: WARN/ImageView(1465): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791) 05-05 13:46:17.132: WARN/ImageView(1465): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549) 05-05 13:46:17.132: WARN/ImageView(1465): at dalvik.system.NativeStart.main(Native Method) 05-05 13:46:17.161: WARN/ResourceType(1465): No package identifier when getting value for resource number 0x00000001 05-05 13:46:17.192: WARN/ImageView(1465): Unable to find resource: 1 05-05 13:46:17.192: WARN/ImageView(1465): android.content.res.Resources$NotFoundException: Resource ID #0x1 05-05 13:46:17.192: WARN/ImageView(1465): at android.content.res.Resources.getValue(Resources.java:896) 05-05 13:46:17.192: WARN/ImageView(1465): at android.content.res.Resources.getDrawable(Resources.java:584) 05-05 13:46:17.192: WARN/ImageView(1465): at android.widget.ImageView.resolveUri(ImageView.java:485) 05-05 13:46:17.192: WARN/ImageView(1465): at android.widget.ImageView.onMeasure(ImageView.java:577) 05-05 13:46:17.192: WARN/ImageView(1465): at android.view.View.measure(View.java:7703) 05-05 13:46:17.192: WARN/ImageView(1465): at android.widget.Gallery.setUpChild(Gallery.java:795) 05-05 13:46:17.192: WARN/ImageView(1465): at android.widget.Gallery.makeAndAddView(Gallery.java:747) 05-05 13:46:17.192: WARN/ImageView(1465): at android.widget.Gallery.layout(Gallery.java:627) 05-05 13:46:17.192: WARN/ImageView(1465): at android.widget.Gallery.onLayout(Gallery.java:339) 05-05 13:46:17.192: WARN/ImageView(1465): at android.view.View.layout(View.java:6569) 05-05 13:46:17.192: WARN/ImageView(1465): at android.widget.AbsoluteLayout.onLayout(AbsoluteLayout.java:120) 05-05 13:46:17.192: WARN/ImageView(1465): at android.view.View.layout(View.java:6569) 05-05 13:46:17.192: WARN/ImageView(1465): at android.widget.FrameLayout.onLayout(FrameLayout.java:333) 05-05 13:46:17.192: WARN/ImageView(1465): at android.view.View.layout(View.java:6569) 05-05 13:46:17.192: WARN/ImageView(1465): at android.widget.FrameLayout.onLayout(FrameLayout.java:333) 05-05 13:46:17.192: WARN/ImageView(1465): at android.view.View.layout(View.java:6569) 05-05 13:46:17.192: WARN/ImageView(1465): at android.widget.FrameLayout.onLayout(FrameLayout.java:333) 05-05 13:46:17.192: WARN/ImageView(1465): at android.view.View.layout(View.java:6569) 05-05 13:46:17.192: WARN/ImageView(1465): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1119) 05-05 13:46:17.192: WARN/ImageView(1465): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:998) 05-05 13:46:17.192: WARN/ImageView(1465): at android.widget.LinearLayout.onLayout(LinearLayout.java:918) 05-05 13:46:17.192: WARN/ImageView(1465): at android.view.View.layout(View.java:6569) 05-05 13:46:17.192: WARN/ImageView(1465): at android.widget.FrameLayout.onLayout(FrameLayout.java:333) 05-05 13:46:17.192: WARN/ImageView(1465): at android.view.View.layout(View.java:6569) 05-05 13:46:17.192: WARN/ImageView(1465): at android.widget.FrameLayout.onLayout(FrameLayout.java:333) 05-05 13:46:17.192: WARN/ImageView(1465): at android.view.View.layout(View.java:6569) 05-05 13:46:17.192: WARN/ImageView(1465): at android.widget.FrameLayout.onLayout(FrameLayout.java:333) 05-05 13:46:17.192: WARN/ImageView(1465): at android.view.View.layout(View.java:6569) 05-05 13:46:17.192: WARN/ImageView(1465): at android.view.ViewRoot.performTraversals(ViewRoot.java:979) 05-05 13:46:17.192: WARN/ImageView(1465): at android.view.ViewRoot.handleMessage(ViewRoot.java:1613) 05-05 13:46:17.192: WARN/ImageView(1465): at android.os.Handler.dispatchMessage(Handler.java:99) 05-05 13:46:17.192: WARN/ImageView(1465): at android.os.Looper.loop(Looper.java:123) 05-05 13:46:17.192: WARN/ImageView(1465): at android.app.ActivityThread.main(ActivityThread.java:4203) 05-05 13:46:17.192: WARN/ImageView(1465): at java.lang.reflect.Method.invokeNative(Native Method) 05-05 13:46:17.192: WARN/ImageView(1465): at java.lang.reflect.Method.invoke(Method.java:521) 05-05 13:46:17.192: WARN/ImageView(1465): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791) 05-05 13:46:17.192: WARN/ImageView(1465): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549) 05-05 13:46:17.192: WARN/ImageView(1465): at dalvik.system.NativeStart.main(Native Method) Du coup l'image ne s'affiche pas... Si quelqu'un a la solution je suis preneur ! Merci par avance pour votre aide. Modifié 6 mai 2010 par Flo07 Citer Lien vers le commentaire Partager sur d’autres sites More sharing options...
Fluckysan Posté(e) 5 mai 2010 Share Posté(e) 5 mai 2010 Es-tu sûr que tu as un ImageView avec cet id : R.id.Imagedlduweb Sinon essaye de lancer ton appli en mode débug et vérifie s'il fait une exception dans ton telechargerImage Citer Lien vers le commentaire Partager sur d’autres sites More sharing options...
Flo07 Posté(e) 5 mai 2010 Auteur Share Posté(e) 5 mai 2010 C'est tout bon [color=red]sa[/color] fonctionne. Le problème venait apparemment du placement de la première ligne dans mon code. Citer Lien vers le commentaire Partager sur d’autres sites More sharing options...
Flo07 Posté(e) 6 mai 2010 Auteur Share Posté(e) 6 mai 2010 Re bonjour à tous, Maintenant que j'arrive à télécharger mon image correctement, je souhaite l'intégrer à une gallery. J'ai suivit le tuto de Google sur le sujet, ce qui me permet d'avoir un truc plutot sympa mais qui ne prend en charge que les image contenue dans mon drawable... Voici le code : public class ImageAdapter extends BaseAdapter { int mGalleryItemBackground; private Context mContext; int t; private Integer[] mImageIds = { R.drawable.clio, R.drawable.alfa147, R.drawable.a4, }; public ImageAdapter(Context c) { mContext = c; } public int getCount() { return mImageIds.length; } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { ImageView i = new ImageView(mContext); i.setImageResource(mImageIds[position]); // i.setImageBitmap(telechargerImage("http://filer.kiloutou.fr//Upload/Materiel/Image140/camben_140.gif")); i.setLayoutParams(new Gallery.LayoutParams(150, 100)); i.setScaleType(ImageView.ScaleType.FIT_XY); i.setBackgroundResource(mGalleryItemBackground); return i; } } Lorsque je laisse la ligne : i.setImageBitmap(telechargerImage("http://filer.kiloutou.fr//Upload/Materiel/Image140/camben_140.gif")); Sa met bien l'image mais à la place des 3 autres. C'est à dire que l'image apparait 3 fois de suite. Si quelqu'un a une solution ... Merci par avance Citer Lien vers le commentaire Partager sur d’autres sites More sharing options...
Recommended Posts
Rejoignez la conversation
Vous pouvez poster maintenant et vous enregistrez plus tard. Si vous avez un compte, connectez-vous maintenant pour poster.