求助 MyAsynTask实例化时ImageTest的构造函数没有执行,mProgressBar.setVisibility(View.VISIBLE);这一句报空指针异常
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Log.v("tag","执行mainactivity");
setContentView(R.layout.activity_main);
// ImageTest textd= new ImageTest();
MyAsynTask task =new ImageTest().new MyAsynTask();
task.execute();
}
public void LOADIMAGE(View view){
startActivity(new Intent(this,ImageTest.class));
}
}
public class ImageTest extends Activity{
private ImageView mImageView;
private ProgressBar mProgressBar;
private static String URL="http://img.my.csdn.net/uploads/201504/12/1428806103_9476.png";
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.image);
mImageView=(ImageView) findViewById(R.id.imageView);
mProgressBar=(ProgressBar) findViewById(R.id.progressBar);
Log.v("tag","构造函数已执行");
//设置传递进去的参数
new MyAsynTask().execute(URL);
}
class MyAsynTask extends AsyncTask<String,Void,Bitmap>{
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
Log.v("tag","这里还好");
mProgressBar.setVisibility(View.VISIBLE);
}
@Override
protected void onPostExecute(Bitmap bitmap) {
// TODO Auto-generated method stub
super.onPostExecute(bitmap);
mProgressBar.setVisibility(View.GONE);
mImageView.setImageBitmap(bitmap);
}
@Override
protected Bitmap doInBackground(String... arg0) {
// TODO Auto-generated method stub
//获取传递进来的参数
Log.v("tag","传入参数长度"+arg0.length);
String url =arg0[0];
Bitmap bitmap=null;
URLConnection connection;
InputStream is;
try {
connection =new URL(url).openConnection();
is=connection.getInputStream();
BufferedInputStream bis=new BufferedInputStream(is);
Thread.sleep(3000);
bitmap=BitmapFactory.decodeStream(bis);//将输入流解析为bitmap
is.close();
bis.close();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return bitmap;
}
}
}
求问哪里出了问题?