我有一个小问题。我正在尝试使用片段创建布局,但是当我调用该setAdapter
方法时,我有一个 Java NullPointerException
,但找不到错误。谢谢大家!
班级代码
public class Agenda extends FragmentActivity{
PagerAdapter mPagerAdapter;
ViewPager mViewPager;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.agenda_sw);
mPagerAdapter = new PagerAdapter(getSupportFragmentManager());
// Set up the ViewPager with the sections adapter.
mViewPager = (ViewPager) findViewById(R.id.agendaPager);
mViewPager.setAdapter(mPagerAdapter); //Line 32, the error is on this line.
}
xml代码
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/agenda_sw"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
日志猫
03-04 11:06:14.686: E/AndroidRuntime(1356): FATAL EXCEPTION: main
03-04 11:06:14.686: E/AndroidRuntime(1356): java.lang.RuntimeException: Unable to start activity ComponentInfo{conf.main/conf.main.Agenda}: java.lang.NullPointerException
...
03-04 11:06:14.686: E/AndroidRuntime(1356): Caused by: java.lang.NullPointerException
03-04 11:06:14.686: E/AndroidRuntime(1356): at conf.main.Agenda.onCreate(Agenda.java:32)