我想ArrayAdapter
在我的类中实现一个Fragment
不扩展的Activity
。
问题是ArrayAdapter的构造函数的第一个参数要传入什么。
ArrayAdapter<String> myAdapter = new ArrayAdapter<String>(<what place here>,android.R.layout.simple_list_item1,anyarraylist);
现在我应该如何处理第一个参数?我试图通过
getActivity().getApplicationContext()
在第一个参数中,但代码崩溃了。
请帮帮我。
我的日志猫:
03-17 03:33:08.029: E/AndroidRuntime(596): FATAL EXCEPTION: main
03-17 03:33:08.029: E/AndroidRuntime(596): java.lang.NullPointerException
03-17 03:33:08.029: E/AndroidRuntime(596): at com.search.pages.SearchResults.onCreateView(SearchResults.java:92)
03-17 03:33:08.029: E/AndroidRuntime(596): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:871)
03-17 03:33:08.029: E/AndroidRuntime(596): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1083)
03-17 03:33:08.029: E/AndroidRuntime(596): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:635)
03-17 03:33:08.029: E/AndroidRuntime(596): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1431)
03-17 03:33:08.029: E/AndroidRuntime(596): at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:420)
03-17 03:33:08.029: E/AndroidRuntime(596): at android.os.Handler.handleCallback(Handler.java:587)
03-17 03:33:08.029: E/AndroidRuntime(596): at android.os.Handler.dispatchMessage(Handler.java:92)
03-17 03:33:08.029: E/AndroidRuntime(596): at android.os.Looper.loop(Looper.java:123)
03-17 03:33:08.029: E/AndroidRuntime(596): at android.app.ActivityThread.main(ActivityThread.java:4627)
03-17 03:33:08.029: E/AndroidRuntime(596): at java.lang.reflect.Method.invokeNative(Native Method)
03-17 03:33:08.029: E/AndroidRuntime(596): at java.lang.reflect.Method.invoke(Method.java:521)
03-17 03:33:08.029: E/AndroidRuntime(596): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
03-17 03:33:08.029: E/AndroidRuntime(596): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
03-17 03:33:08.029: E/AndroidRuntime(596): at dalvik.system.NativeStart.main(Native Method)