1
我有一個小問題。我試圖創建一個帶有片段的佈局,但是當我調用setAdapter
方法時,我有一個Java NullPointerException
,我找不到該錯誤。 謝謝大家!Android - 在setAdapter的NullPointerException ViewPager
類代碼
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"
/>
logcat的
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)
好的,我是一個白癡:)謝謝 – user2110763 2013-03-04 14:20:55
接受我的回答,如果它幫助你) – Leonidos 2013-03-04 14:43:15
這是在我的意圖,但我不得不等待幾分鐘才能做到這一點 – user2110763 2013-03-04 14:55:40