import android.app.Activity; import android.os.Bundle; import android.os.Handler; import android.widget.ImageView; import android.widget.TextView; 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 mRunnable=new myRunnable(); class myRunnable implements Runnable{ public void run() { index++; index=index%6; imageView.setImageResource(imgid[index]); handler.postDelayed(mRunnable, 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(mRunnable, 1000); } }
运行模拟器报出空指针异常,而且是:
imageView.setImageResource(imgid[index]);报的错,求大神指教我错在哪里了!?
step_Android
非学霸
相关分类