I have an issue getting NullPointer exception when I’m trying to get a checkbox from another class, not a new checkbox, the same.
This is what I want to do:
/*My First class*/
class Object1 {
private Checkbox checkbox;
private String texto="";
public Object1(Context context, Texto texto){
this.texto=texto;
checkbox=new checkbox(context);
}
//Here is How I'm returning the checkbox
public CheckBox getCheckBox(){
return checkbox;
}
}
/*My Second class where I'm trying to set a listener to the checkbox*/
Class Object2{
public Object2(){
--->> new Object1.getCheckBox().setOnCheckedChangeListener(listener);
}
}
How can I get it?
I believe you failed to use your constuctor.
Shouldn’t:
Be:
?
In the first instance I’m pretty sure you’re not instantiating it properly at all, as it would at least have to be new Object1(), but then you’d get compiler errors complaining that you didn’t use the proper constructor… so you must be accidentally creating a reference to the class itself.