2

I'm using "android.support.v4.view.ViewPager" in my app. And I'm using this code to initializing Tabs.

    mCollectionPagerAdapter = new CollectionPagerAdapter(getSupportFragmentManager());
    final ActionBar actionBar = getActionBar();
    actionBar.setHomeButtonEnabled(false);
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mCollectionPagerAdapter);
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() 
    {
        @Override
        public void onPageSelected(int position) 
        {
            actionBar.setSelectedNavigationItem(position);
        }
    });


    for (int i = 0; i < mCollectionPagerAdapter.getCount(); i++) 
    {
        actionBar.addTab(actionBar.newTab().setText(mCollectionPagerAdapter.getPageTitle(i)).setTabListener(this));
    }

In the Tab3 Layout I created listview. Now when I call list view by this coding null pointer exception showing:

    ListView songsListView = (ListView)findViewById(R.id.NotificationslistView);
    String[] songsArray = new String[10];       
    for(int i=0; i < songsArray.length; i++)
    {
        songsArray[i] = "Song " + i;
    }
    ArrayAdapter arrayAdapter = new ArrayAdapter(view.getContext(), android.R.layout.simple_list_item_1, songsArray);

Note 1: all that codes in the main activity calling after oncreate method. Note 2: I'm using this code to inflate Tab3 layout, and it solve Nullexceptionpointer error, but dosn't show anything in listview !!

    View view; 
    LayoutInflater inflater = (LayoutInflater)getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    view = inflater.inflate(R.layout.tab3, null);           
    ListView songsListView = (ListView) view.findViewById(R.id.NotificationslistView);
bebosh
  • 806
  • 10
  • 25
  • Possible duplicate of [What is a Null Pointer Exception, and how do I fix it?](http://stackoverflow.com/questions/218384/what-is-a-null-pointer-exception-and-how-do-i-fix-it) – Albireo Mar 07 '16 at 08:54

0 Answers0