我正在尝试在片段类中使用 jfeinstein10 SlidingMenu。
public class ConversionFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.activity_conversion, container, false);
super.onCreate(savedInstanceState);
SlidingMenu menu = new SlidingMenu(BaseActivity.context);
menu.setMode(SlidingMenu.LEFT);
menu.setBehindOffsetRes(R.dimen.slidingmenu_offset);
menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN);
menu.attachToActivity((Activity) BaseActivity.context, SlidingMenu.SLIDING_WINDOW);
menu.setMenu(R.layout.list);
ListView lv = (ListView) rootView.findViewById(R.id.listView1);
String[] values = new String[] { "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten" };
ArrayAdapter<String> adapter = new ArrayAdapter<String>(rootView.getContext().getApplicationContext(),
android.R.layout.simple_list_item_1, android.R.id.text1, values);
lv.setAdapter(adapter);
return rootView;
}
}
和我的 list.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
我在lv.setAdapter(adapter);
这可能是什么原因得到一个空点异常?
这甚至是使用 jfeinstein10 SlidingMenu 的正确方法吗?
04-18 19:15:36.345: D/myapp(19089): java.lang.Exception
04-18 19:15:36.345: D/myapp(19089): at com.example.app1.ConversionFragment.onCreateView(ConversionFragment.java:44)
04-18 19:15:36.345: D/myapp(19089): at android.app.Fragment.performCreateView(Fragment.java:1695)
04-18 19:15:36.345: D/myapp(19089): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:885)
04-18 19:15:36.345: D/myapp(19089): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1057)
04-18 19:15:36.345: D/myapp(19089): at android.app.BackStackRecord.run(BackStackRecord.java:682)
04-18 19:15:36.345: D/myapp(19089): at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1435)
04-18 19:15:36.345: D/myapp(19089): at android.app.FragmentManagerImpl$1.run(FragmentManager.java:441)
04-18 19:15:36.345: D/myapp(19089): at android.os.Handler.handleCallback(Handler.java:725)
04-18 19:15:36.345: D/myapp(19089): at android.os.Handler.dispatchMessage(Handler.java:92)
04-18 19:15:36.345: D/myapp(19089): at android.os.Looper.loop(Looper.java:137)
04-18 19:15:36.345: D/myapp(19089): at android.app.ActivityThread.main(ActivityThread.java:5041)
04-18 19:15:36.345: D/myapp(19089): at java.lang.reflect.Method.invokeNative(Native Method)
04-18 19:15:36.345: D/myapp(19089): at java.lang.reflect.Method.invoke(Method.java:511)
04-18 19:15:36.345: D/myapp(19089): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
04-18 19:15:36.345: D/myapp(19089): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
04-18 19:15:36.345: D/myapp(19089): at dalvik.system.NativeStart.main(Native Method)
04-18 19:15:38.001: D/AndroidRuntime(19089): Shutting down VM
04-18 19:15:38.001: W/dalvikvm(19089): threadid=1: thread exiting with uncaught exception (group=0x41e8b930)
04-18 19:15:38.025: E/AndroidRuntime(19089): FATAL EXCEPTION: main
04-18 19:15:38.025: E/AndroidRuntime(19089): java.lang.NullPointerException
04-18 19:15:38.025: E/AndroidRuntime(19089): at com.example.app1.ConversionFragment.onCreateView(ConversionFragment.java:45)
04-18 19:15:38.025: E/AndroidRuntime(19089): at android.app.Fragment.performCreateView(Fragment.java:1695)
04-18 19:15:38.025: E/AndroidRuntime(19089): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:885)
04-18 19:15:38.025: E/AndroidRuntime(19089): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1057)
04-18 19:15:38.025: E/AndroidRuntime(19089): at android.app.BackStackRecord.run(BackStackRecord.java:682)
04-18 19:15:38.025: E/AndroidRuntime(19089): at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1435)
04-18 19:15:38.025: E/AndroidRuntime(19089): at android.app.FragmentManagerImpl$1.run(FragmentManager.java:441)
04-18 19:15:38.025: E/AndroidRuntime(19089): at android.os.Handler.handleCallback(Handler.java:725)
04-18 19:15:38.025: E/AndroidRuntime(19089): at android.os.Handler.dispatchMessage(Handler.java:92)
04-18 19:15:38.025: E/AndroidRuntime(19089): at android.os.Looper.loop(Looper.java:137)
04-18 19:15:38.025: E/AndroidRuntime(19089): at android.app.ActivityThread.main(ActivityThread.java:5041)
04-18 19:15:38.025: E/AndroidRuntime(19089): at java.lang.reflect.Method.invokeNative(Native Method)
04-18 19:15:38.025: E/AndroidRuntime(19089): at java.lang.reflect.Method.invoke(Method.java:511)
04-18 19:15:38.025: E/AndroidRuntime(19089): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
04-18 19:15:38.025: E/AndroidRuntime(19089): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
04-18 19:15:38.025: E/AndroidRuntime(19089): at dalvik.system.NativeStart.main(Native Method)
04-18 19:15:38.040: W/ActivityManager(389): Force finishing activity com.example.app1/.BaseFragment