class PlayAreaView extends View{
private static final String DEBUG_TAG = "PlayAreaView";
private SeekBar sizeSlider;
private int xMin = 0;
private int xMax;
private int yMin = 0;
private int yMax;
private Rect rect;
private GestureDetector gestures;
private Paint p = new Paint();
private int side = 50;
public PlayAreaView(Context context){
super(context);
rect = new Rect(0,0,side,side);
p.setARGB(255, 255, 255, 255);
GestureListener listener = new GestureListener(this);
gestures = new GestureDetector(listener);
sizeSlider = (SeekBar) findViewById(R.id.seek);
//sizeSlider.setOnSeekBarChangeListener(listener);
}
I am new to developing on Android and am having trouble figuring out what is wrong here. I am getting a NullPointerException at the commented out line. I believe it is because I am asking to findViewById in a class that is not the main activity. If this is indeed the problem how can I access UI elements from this class.
As you have set up, findViewById(R.id.seek) will search for a subview with ID equal to R.id.seek within PlayAreaView, which does not exist since you seem to have the SeekBar in your main layout.
If you must access The SeekBar from within this view, pass in a reference to it while instantiating it, e.g., in the main activity
and in PlayAreaView,
then, the SeekBar instance can be accessed through the instance variable sizeSlider from PlaAreaView.