Next item displayed from array instead of the expected value

后端 未结 1 1920
终归单人心
终归单人心 2021-01-24 18:49

This is a very basic java question, I have an array of strings

String[] navTitles = new String[] {Home, HR, company, joiner, next};

These title

相关标签:
1条回答
  • 2021-01-24 19:40

    try below code:-

    Error occur because index value reach more than the index.

    private void displayView(int position) 
    {
        Fragment fragment = null;
        position = position % length; //length of your array 
    
        if(position==0)
        {
            fragment = new HomeFragment(SPHostUrl,encodedAccountName,deviceAuthKey,usersname,avatarUrl, fullName,getApplicationContext(),myFinalNewsList);
        }
        else
        {
            String myPosition = null;
    
            myPosition =  navDrawerItems.get(position).getTitle(); //Line 600
    
    
            companyNewsList = Lists.newArrayList(Collections2.filter(myFinalNewsList, new ArticleFilter(myPosition)));
             fragment = new HomeFragment(SPHostUrl,encodedAccountName,deviceAuthKey,usersname,avatarUrl, fullName,getApplicationContext(),companyNewsList);
    
        }
    }
    

    above code works fine at my end because it makes position under array length .

    0 讨论(0)
提交回复
热议问题