Hhandler 空指针异常!
public class HandlerActivity extends Activity { private TextView textView; private Handler handler= new Handler(); private ImageView imageView; private int imgid[]={R.drawable.a,R.drawable.b,R.drawable.c,R.drawable.e,R.drawable.f,R.drawable.g}; private int index; private myRunnable my1=new myRunnable(); class myRunnable implements Runnable{ public void run() { index++; index=index%6; imageView.setImageResource(imgid[index]); handler.postDelayed(my1, 1000); } } public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); textView=(TextView) findViewById(R.id.textView1); imageView=(ImageView) findViewById(R.id.imageView1); handler.postDelayed(my1, 1000); } }
控制台上显示空指针异常而且是这句:imageView.setImageResource(imgid[index]);出错。请问我错在什么地方了?