Java和Android編程相對比較新,任何人都可以幫助我爲什麼得到NullPointerException
?Android NullPointer錯誤片段自定義類?
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;
}
}}
非常簡單的代碼,我知道,但我不知道我哪裏出錯了?謝謝你的幫助 。
將來,如果您拋出任何類型的異常,您應該發佈日誌而不是隻發佈異常的名稱。你的日誌將指向一個特定的代碼行,它最終會對你和任何試圖幫助你的人有用。 – adneal 2012-07-16 18:33:06