フラグメントのコンテキストの使用に関する質問があります。私の問題は、私は常にNullpointerExceptionを取得することです。ここで私は何ですか:私のFragmentの私のコンテキストはなぜヌルですか?
SherlockFragmentを拡張するクラスを作成します。このクラスでは、私は別のヘルパークラスのインスタンスを持っている:ここでは
public class Fragment extends SherlockFragment {
private Helper helper = new Helper(this.getActivity());
// More code ...
}
は、他のヘルパークラスの抽出物である:私は()などcontext.getResources()context.someMethod
を呼び出す
public class Helper {
public Helper(Context context) {
this.context = context;
}
// More code ...
}
毎回私が得ますNullPointerException何故ですか?
フラグメントを初期化するときに 'SherlockFragment#activity'のように見えますが、後のフェーズで注入されるので、コンストラクタで' null'となります。 –