[SOLVED] Null pointer exception
Basically, my code is like this:
Code:
public class Viewer()
{
private ArrayList<Button> buttonsList;
private Button button1;
public Viewer()
{
buttonsList = new ArrayList<Button>();
addButtons();
}
public void addButtons()
{
//other code emitted
button1 = new Button("title");
if (button1 != null)
{
buttonsList.add(button1); **
}
}
It compiles, but I get a run time error saying there's a null pointer exception where I've put the **. I'm not really sure what the problem is, I've initialised button1 and my array list so neither are null, and I've used an if statement so it only adds to array list if button1 is NOT null. i've tried initializing button1 to null, nothing seems to be working.
Any suggestions would be much appreciated!