Ajouter une image comme "background" dans un ''TextView" dans le code Java ?
Bonsoir,
désolé pour le dérangement.
je veux afficher une image comme fond "background" d'un TextView mais il y a un problème quelque part dans mon code , le logcat affiche java.lang.NullPointerException
mais le problème résout lorsque je change TextView par ImageView et "setBackgroundDrawable" par "setImageDrawable"
Est ce que quelqu'un peut m'aider svp?
Merci d'avance.
voila mon code:
Dans onCreate :
Code:
1 2 3 4 5 6 7 8 9 10 11 12
|
Thread th1=new Thread(new Runnable() {
String imageUrl = "http://192.168.56.2/photo/cdeNonT.php?id=1";
TextView image = (TextView) findViewById(R.id.col2);
@Override
public void run() {
Drawable drw =LoadImageFromWebOperations(imageUrl);
image.setBackgroundDrawable(drw);
}
});
th1.start(); |
la méthode LoadImageFromWebOperations :
Code:
1 2 3 4 5 6 7 8 9 10 11
|
private Drawable LoadImageFromWebOperations(String strPhotoUrl) {
try {
InputStream is = (InputStream) new URL(strPhotoUrl).getContent();
Drawable d = Drawable.createFromStream(is, "src name");
return d;
} catch (Exception e) {
System.out.println("Exc=" + e);
return null;
}
} |