スーパーコンストラクターを渡して this を停止する方法を見つけようとしていますがNPE
、誰か助けてもらえますか?
MainActivity.java
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (hasFocus) {
((DownloadFragment) downloads).refreshlist();
}
}
ダウンロードFragment.java
public class MyAdapter extends ArrayAdapter<AdapterItem> {
public MyAdapter(Context context, int textviewid) {
super(context, textviewid); // NPE here
}
public void refreshlist() {
items.clear();
adapter = new MyAdapter(getActivity(), 0);
// ...
}
}
例外 :
java.lang.NullPointerException
at android.widget.ArrayAdapter.init(ArrayAdapter.java:310)
at android.widget.ArrayAdapter.<init>(ArrayAdapter.java:104)
at com.DownloadFragment$MyAdapter.<init>(DownloadFragment.java:142)
at com.DownloadFragment.refreshlist(DownloadFragment.java:479)
at com.MainActivity.onWindowFocusChanged(MainActivity.java:387)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onWindowFocusChanged(PhoneWindow.java:2466)
at android.view.View.dispatchWindowFocusChanged(View.java:7456)
at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:935)
at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:3264)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:153)
at android.app.ActivityThread.main(ActivityThread.java:5297)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
これを行った後、refreshList() メソッドの次の行は null になります。
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); アダプタ = 新しい MyAdapter(getActivity(), 0); }
ダウンロードFragment.java
Cursor a = mDbHelper.getEachDownload(2);