Android ExpandableListView为空
我是android新手,我一直在尝试使用jfeinstein滑动菜单和可扩展列表。 我的问题是,每次使用findViewById作为expandablelist时,我都会得到null 这是我的密码 主要活动Android ExpandableListView为空,android,nullpointerexception,slidingmenu,jfeinstein,Android,Nullpointerexception,Slidingmenu,Jfeinstein,我是android新手,我一直在尝试使用jfeinstein滑动菜单和可扩展列表。 我的问题是,每次使用findViewById作为expandablelist时,我都会得到null 这是我的密码 主要活动 protected void onCreate(Bundle savedInstanceState) { try{ super.onCreate(savedInstanceState); setContentView(R.layout.acti
protected void onCreate(Bundle savedInstanceState) {
try{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.app = (App) getApplication();
app.menu = new SlidingMenu(app);
app.menu.setMode(SlidingMenu.LEFT);
app.menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
app.menu.setFadeDegree(0.50f);
app.menu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
app.menu.setShadowDrawable(R.drawable.shadow);
app.menu.setShadowWidthRes(R.dimen.shadow_width);
app.menu.setBehindOffsetRes(R.dimen.slidingmenu_offset);
app.menu.setEnabled(true);
app.adapter = new SlideMenuList(this, app, parent, child);
app.listView = (ExpandableListView) app.menu.findViewById(R.id.slide_list);
app.listView.setAdapter(app.adapter);
app.listView.setOnChildClickListener(app.adapter);
app.listView.setOnGroupExpandListener(app.adapter);
android.support.v7.app.ActionBar ac = getSupportActionBar();
ac.setHomeButtonEnabled(true);
init();
}catch(Exception e){
e.printStackTrace();
}
活动\u main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/splash_screen"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:animateLayoutChanges="true"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.jaggz.gurudawaraapp.MainActivity" >
<FrameLayout
android:id="@+id/frame_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" >
</FrameLayout>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<ExpandableListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/slide_list"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</ExpandableListView>
请提供帮助尝试将可扩展列表.xml的代码移动到活动\u main.xml中尝试以下操作:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/splash_screen"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:animateLayoutChanges="true"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.jaggz.gurudawaraapp.MainActivity" >
<FrameLayout
android:id="@+id/frame_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" >
</FrameLayout>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<ExpandableListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/slide_list"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</ExpandableListView>
app.menu.setBehindOffsetRes(R.dimen.slidingmenu_offset);
app.menu.setEnabled(true);
app.adapter = new SlideMenuList(this, app, parent, child);
**app.listView = (ExpandableListView) app.menu.findViewById(R.id.slidingmenu_view);**
app.listView.setAdapter(app.adapter);
app.listView.setOnChildClickListener(app.adapter);
app.listView.setOnGroupExpandListener(app.adapter);
这是MainActivity.java:onCreateapp.listView=(ExpandableListView)app.menu.findViewById(R.id.slide\u列表)中的第64行;