My Nullpointer expection has me stumped. I am getting nullpointer exception at FindViewByID. Here is my piece of code
public class numberActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.number);
}
ImageView portrait = (ImageView) findViewById(R.id.numberImage);
public void numberClick(View v) {
switch(v.getId()){
case R.drawable.numberone:
portrait.setImageResource(R.drawable.numbertwo);
break;
case R.drawable.numbertwo:
portrait.setImageResource(R.drawable.numberthree);
break;
}
}
}
My number.xml is here
<ImageView
android:id="@+id/numberImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/numberone"
android:onClick="numberClick" />
Very simple code i think, but the null pointer exception is frustrating me since last night. Any help is appreciated.
This line has to be in the onCreate method.
Like this