我的代码有错误的问题,
public class MainActivity2 extends Activity {
EditText et;
ImageView iv;
Runnable stream;
Handler hand = new Handler();
Runnable run ;
public Button tombol2;
@SuppressLint("NewApi")
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
Intent intent = getIntent();
String url= intent.getStringExtra("URL");
tombol2 = (Button) findViewById(R.id.button2);
iv = (ImageView) findViewById(R.id.imageView1);
Drawable d1=LoadImageFromWebOperations(url);
iv.setImageDrawable(d1);
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
iv.setImageDrawable(d1);
}
}, 10000);
}
private Drawable LoadImageFromWebOperations(String url)
{
try
{
InputStream is = (InputStream) new URL(url).getContent();
Drawable d = Drawable.createFromStream(is, "src name");
return d;
}catch (Exception e) {
System.out.println("Exc="+e);
return null;
}
}
}
使用 runnable 和处理程序函数后,我在应用程序中看不到图像,我在 void 运行时出现错误,iv.setImageDrawable(d1);
如何解决?显示并运行该图像