我在操作欄上使用了菜單項。但是在創建方法中,它給了我空指針異常。請幫助在getActionBar方法中獲取空指針異常
感謝
這裏是onCreate方法的代碼
// TODO Auto-generated method stub
super.onCreate(paramBundle);
setContentView(R.layout.activity_home);
final ActionBar localActionBar=getActionBar();
localActionBar.setNavigationMode(2);
this.mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager());
this.mViewPager = ((ViewPager)findViewById(R.id.pager));
this.mViewPager.setAdapter(this.mSectionsPagerAdapter);
this.mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener()
{
public void onPageSelected(int paramAnonymousInt)
{
localActionBar.setSelectedNavigationItem(paramAnonymousInt);
}
});
for (int i = 0; i < this.mSectionsPagerAdapter.getCount(); i++)
{
localActionBar.addTab(localActionBar.newTab().setText(this.mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
}
}
和日誌貓錯誤
log01-15 13:37:09.092: E/AndroidRuntime(15604): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.chronos.cricketgraph/com.chronos.cricketgraph.HomeActivity}: java.lang.NullPointerException
01-15 13:37:09.092: E/AndroidRuntime(15604): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2114)
01-15 13:37:09.092: E/AndroidRuntime(15604): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2139)
01-15 13:37:09.092: E/AndroidRuntime(15604): at android.app.ActivityThread.access$700(ActivityThread.java:143)
01-15 13:37:09.092: E/AndroidRuntime(15604): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1241)
01-15 13:37:09.092: E/AndroidRuntime(15604): at android.os.Handler.dispatchMessage(Handler.java:99)
01-15 13:37:09.092: E/AndroidRuntime(15604): at android.os.Looper.loop(Looper.java:137)
01-15 13:37:09.092: E/AndroidRuntime(15604): at android.app.ActivityThread.main(ActivityThread.java:4960)
01-15 13:37:09.092: E/AndroidRuntime(15604): at java.lang.reflect.Method.invokeNative(Native Method)
01-15 13:37:09.092: E/AndroidRuntime(15604): at java.lang.reflect.Method.invoke(Method.java:511)
01-15 13:37:09.092: E/AndroidRuntime(15604): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
01-15 13:37:09.092: E/AndroidRuntime(15604): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
01-15 13:37:09.092: E/AndroidRuntime(15604): at dalvik.system.NativeStart.main(Native Method)
01-15 13:37:09.092: E/AndroidRuntime(15604): Caused by: java.lang.NullPointerException
01-15 13:37:09.092: E/AndroidRuntime(15604): at com.chronos.cricketgraph.HomeActivity.onCreate(HomeActivity.java:48)
01-15 13:37:09.092: E/AndroidRuntime(15604): at android.app.Activity.performCreate(Activity.java:5203)
01-15 13:37:09.092: E/AndroidRuntime(15604): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
'
做你的活動有一個動作條?你在使用其他主題嗎? –