Relatively new to Java and Android programming can anybody help as to why I’m getting a NullPointerException?
public class DpsFragment extends Fragment {
Weapon weppy;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
weppy.setMaxdmg(200);
weppy.setMindmg(100);
TextView tv= (TextView) getView().findViewById(R.id.textView1);
tv.setText("hello");
return inflater.inflate(R.layout.dpsfrag, container, false);
}
public class Weapon {
private int mindmg;
private int maxdmg;
public Weapon(int mindmg, int maxdmg) {
this.setMindmg(mindmg);
this.setMaxdmg(maxdmg);
}
public int getMindmg() {
return mindmg;
}
public void setMindmg(int mindmg) {
this.mindmg = mindmg;
}
public int getMaxdmg() {
return maxdmg;
}
public void setMaxdmg(int maxdmg) {
this.maxdmg = maxdmg;
}
}}
Very simple code, I know, but I have no idea where I have gone wrong? Thanks for any help .
weppy is nullso NPE …i think you forgot to initialize it.it may be
weppy = new Weapon(mindmg,maxdmg);ALSO