直接闪退,不知道为什么
package com.example.yibu;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import javax.net.ssl.HttpsURLConnection;
import android.annotation.SuppressLint;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Handler;
import android.os.Message;
import android.widget.ImageView;
//多线程
public class imageLoader {
private ImageView mImageView;
@SuppressLint("HandlerLeak")
private Handler mHandler = new Handler() {
public void handleMessage(Message msg) {
super.handleMessage(msg);
mImageView.setImageBitmap((Bitmap) msg.obj);
}
};
public void showImageByThread(ImageView imageView, final String urlsString) {
mImageView = imageView;
new Thread() {
@Override
public void run() {
super.run();
// 图像加载方法
Bitmap bitmap ;
bitmap= getBitmapFromURL(urlsString);
// 发送出去让handler处理
Message message = Message.obtain();
message.obj = bitmap;
mHandler.sendMessage(message);
}
}.start();
}
public Bitmap getBitmapFromURL(String urlString) {
Bitmap bitmap;
InputStream is = null ;
URL url;
try {
url = new URL(urlString);
HttpsURLConnection connection = (HttpsURLConnection) url
.openConnection();
is = new BufferedInputStream(connection.getInputStream());
bitmap = BitmapFactory.decodeStream(is);
connection.disconnect();
return bitmap;
} catch (java.io.IOException e) {
e.printStackTrace();
}
finally {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}
}