点击Image Test按钮闪退

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);


qkobe
浏览 1410回答 1
1回答

田心枫

空指针
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Android