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);
田心枫
相关分类