com.example.qkobe.asynctask;
android.graphics.Bitmap;
android.graphics.BitmapFactory;
android.os.AsyncTask;
android.os.Bundle;
android.support.v7.app.AppCompatActivity;
android.view.View;
android.widget.ImageView;
android.widget.ProgressBar;
java.io.BufferedInputStream;
java.io.IOException;
java.io.InputStream;
java.net.URL;
java.net.URLConnection;
ImageTest AppCompatActivity {
ImageView ;
ProgressBar ;
String = ;
onCreate(Bundle savedInstanceState) {
.onCreate(savedInstanceState);
= (ImageView)findViewById(R.id.);
= (ProgressBar)findViewById(R.id.);
MyAsyncTask().execute();
}
MyAsyncTask AsyncTask<String,Void,Bitmap>{
onPreExecute() {
.onPreExecute();
.setVisibility(View.);
}
onPostExecute(Bitmap bitmap) {
.onPostExecute(bitmap);
.setImageBitmap(bitmap);
.setVisibility(View.);
}
Bitmap doInBackground(String... params) {
String url = params[];
Bitmap bitmap = ;
URLConnection connection;
InputStream is;
{
connection = URL(url).openConnection();
is = connection.getInputStream();
BufferedInputStream bis = BufferedInputStream(is);
bitmap = BitmapFactory.(bis);
is.close();
bis.close();
}(IOException e){
e.printStackTrace();
}
bitmap;
}
}
}报错为java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ProgressBar.setVisibility(int)' on a null object reference错误行代码为mProgressBar.setVisibility(View.VISIBLE);
添加回答
举报
0/150
提交
取消