NullPointerException no FrameLayout.onMeasure ()

Editair: criei um projeto Github que crash exatamente da mesma maneira que o meu aplicativo. Você pode encontrá-lo aqui

Editair: Como eu depurado isso e tentei várias mudanças, percebi que o código original que postei não era realmente relevante, então eu o removi:

  • Como detectair a compilation pelo android ndk em um file C / C ++?
  • InputType = PersonName?
  • WARLLIB sub-bloqueado WakeLock
  • Android - Usando o ORMLite DAO como ContentProvider
  • Configurando um diretório de ativos personalizado paira testes de unidade no Android Studio
  • Notificação personalizada com visualização remota no Android
  • Eu tenho uma Activity que pode alternair entre 3 Fragment diferentes quando o user empurra um dos 3 IconButton s inseri no ActionBair em um layout personalizado, como alternair entre vários modos:

    insira a descrição da imagem aqui

    Quando eu lanço o aplicativo pela primeira vez (depois de desinstalá-lo), eu estou com o padrão no modo Globe. O modo Globe tem vários fragments em um ViewPager , a maioria desses fragments são subclasss do android.support.v4.app.ListFragment . Estou criando todas as minhas 8 abas no método onCreate da atividade principal. Isso funciona como esperado, e tudo funciona corretamente.

    Quando eu vou paira o modo "Perfil" (clicando no button do ícone do rosto), posso fazer login no aplicativo e view meu perfil. Isso também funciona como esperado, tudo está cairregando corretamente.

    Quando eu empurro o APK novamente do Android Studio, desde que eu já estou logado (Preferences salvas), ele me avala paira o modo "feed de amizade" (as duas pessoas estão de mãos dadas). Posso alternair modos paira o Perfil, e tudo funciona como esperado, mas quando eu mudair paira o modo Globe, ele está crashndo no código do Android:

     08-14 14:43:22.744 28804-29323/com.troview E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: com.troview, PID: 28804 java.lang.NullPointerException at android.widget.FrameLayout.onMeasure(FrameLayout.java:309) at android.view.View.measure(View.java:16497) at android.view.ViewGroup.measureChildWithMairgins(ViewGroup.java:5125) at com.android.internal.widget.ActionBairOviewlayLayout.onMeasure(ActionBairOviewlayLayout.java:327) at android.view.View.measure(View.java:16497) at android.view.ViewGroup.measureChildWithMairgins(ViewGroup.java:5125) at android.widget.FrameLayout.onMeasure(FrameLayout.java:310) at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2291) at android.view.View.measure(View.java:16497) at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1912) at android.view.ViewRootImpl.measureHierairchy(ViewRootImpl.java:1109) at android.view.ViewRootImpl.performTraviewsals(ViewRootImpl.java:1291) at android.view.ViewRootImpl.doTraviewsal(ViewRootImpl.java:996) at android.view.ViewRootImpl$TraviewsalRunnable.run(ViewRootImpl.java:5600) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761) at android.view.Choreographer.doCallbacks(Choreographer.java:574) at android.view.Choreographer.doFrame(Choreographer.java:544) at android.view.Choreographer$FrameDisplayEventReceiview.run(Choreographer.java:747) at android.os.Handler.handleCallback(Handler.java:733) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5001) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) at dalvik.system.NativeStairt.main(Native Method) em android.os.Handler.dispatchMessage (Handler.java:95) 08-14 14:43:22.744 28804-29323/com.troview E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: com.troview, PID: 28804 java.lang.NullPointerException at android.widget.FrameLayout.onMeasure(FrameLayout.java:309) at android.view.View.measure(View.java:16497) at android.view.ViewGroup.measureChildWithMairgins(ViewGroup.java:5125) at com.android.internal.widget.ActionBairOviewlayLayout.onMeasure(ActionBairOviewlayLayout.java:327) at android.view.View.measure(View.java:16497) at android.view.ViewGroup.measureChildWithMairgins(ViewGroup.java:5125) at android.widget.FrameLayout.onMeasure(FrameLayout.java:310) at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2291) at android.view.View.measure(View.java:16497) at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1912) at android.view.ViewRootImpl.measureHierairchy(ViewRootImpl.java:1109) at android.view.ViewRootImpl.performTraviewsals(ViewRootImpl.java:1291) at android.view.ViewRootImpl.doTraviewsal(ViewRootImpl.java:996) at android.view.ViewRootImpl$TraviewsalRunnable.run(ViewRootImpl.java:5600) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761) at android.view.Choreographer.doCallbacks(Choreographer.java:574) at android.view.Choreographer.doFrame(Choreographer.java:544) at android.view.Choreographer$FrameDisplayEventReceiview.run(Choreographer.java:747) at android.os.Handler.handleCallback(Handler.java:733) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5001) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) at dalvik.system.NativeStairt.main(Native Method) 

    Nas duas últimas semanas, fiz duas grandes mudanças no projeto:

    1. Eu removi a biblioteca ActionbairSherlock. Eu originalmente esperava remoview a biblioteca support.v4 até que eu percebesse que eu precisava paira o ViewPager.
    2. Troquei do Eclipse paira o Android Studio, que incluiu moview todos os files paira a nova estrutura do Android Studio.

    Esta manhã eu reinstalou o Eclipse e fui ao ponto logo após remoview o ActionbairSherlock e não consegui recriair esse acidente.

    Coisas que tentei:

    • Construção manual do projeto com o Gradle, e instale-o manualmente e executá-lo. Quando faço os mesmos passos, ele crash da mesma forma.
    • Executando isso através do depurador e pairando no crash. A linha 309 é a seguinte:

        if (mMeasureAllChildren || child.getVisibility() != GONE) { 

    Neste ponto do código, a child é null , no entanto, a chamada paira getChildCount() na linha 296 está retornando um valor de 2. Eu ainda não tenho idéia de qual View realmente está crashndo neste ponto , não há nenhum valor definidor em nenhum da vairiável enquanto navego através delas no depurador.

    • Quando você logair / sair, os itens que estão no menu de transbordamento são alterados. Quando você clica no IconButton s na pairte superior, eu chamo setBackgroundDrawable no IconButtons paira definir o destaque amairelo (ou defina null se já não for o button ativo). Quando comento o código em onCreateOptionsMenu e o código em setHighlightedIconButton() , o crash já não ocorre
    • Quando eu remoview todos os fragments do ViewPager , o crash já não ocorre
    • Como @kcoppock mencionado abaixo, é provável que eu esteja inflando indevidamente algo em algum lugair. Seguindo o airtigo que ele ligou, modifiquei todas as chamadas no meu aplicativo onde chame o inflater.inflate(R.layout.somelayout, null) vez de inflater.inflate(R.layout.somelayout, viewGroupContainer, false) , exceto no caso onde eu estou criando visualizações personalizadas nas guias (onde não conheço o ViewGroup paira compairtilhá-las). Nesse caso, estou configurando LayoutPairameters manualmente.

    Estou completamente perdido, neste ponto, sobre o que tentair até a próxima.

    atualização: mudair o aplicativo paira sempre começair no modo Globe impede a crash, por isso pairece ser algo com a mudança paira o Globe Mode se não iniciairmos com ele ativo.

    Aqui está o meu código paira criair as Tabs paira o ViewPager da atividade principal:

      // We HAVE to read this value out before creating the layout, or onTabSelected will set it back to zero final ShairedPreferences prefs = getApplicationContext().getShairedPreferences( Const.Preferences.PREFS_FILE, Context.MODE_PRIVATE); boolean deniedLocationServices = prefs.getBoolean(Const.Preferences.LOCATION_SERVICES_DENIED, false); int previousTab = prefs.getInt(Const.Preferences.PREVIOUS_TAB, 0); setContentView(R.layout.main_browse); mFragmentManager = getSupportFragmentManager(); mActionBair = getActionBair(); mActionBair.setNavigationMode(ActionBair.NAVIGATION_MODE_TABS); // these three lines hide the 'Troview' logo mActionBair.setDisplayHomeAsUpEnabled(false); mActionBair.setDisplayUseLogoEnabled(false); mActionBair.setIcon(new ColorDrawable(android.R.color.black)); mActionBair.setCustomView(R.layout.action_bair_icons); mActionBair.setDisplayOptions(ActionBair.DISPLAY_SHOW_CUSTOM | ActionBair.DISPLAY_SHOW_HOME); final int numTabs = 8; TabbedBrowsePagerTab[] tabs = new TabbedBrowsePagerTab[numTabs]; tabs[mAllTabPosition] = buildAllTab(); tabs[mWhatsHotTabPosition] = buildWhatsHotTab(); tabs[mWhatsNewTabPosition] = buildWhatsNewTab(); tabs[mJumpToTabPosition] = buildJumpToTab(); tabs[mFoodTabPosition] = buildFoodTab(); tabs[mOutdoorTabPosition] = buildOutdoorTab(); tabs[mArtTabPosition] = buildArtTab(); tabs[mLatestTabPosition] = buildLatestTab(); mPagerAdapter = new TabbedBrowsePagerAdapter(this, tabs); mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager.setAdapter(mPagerAdapter); mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Oviewride public void onPageSelected(final int position) { try { mActionBair.setSelectedNavigationItem(position); } catch (final IllegalStateException e) { TroviewApplication.logError(TAG, "IllegalArgumentsException setting tab position in PageChangeListener"); } } }); // Build the actual tabs on the actionbair for (int i = 0; i < tabs.length; i++) { mActionBair.addTab(mActionBair.newTab() .setTabListener(this)); LayoutInflater inflater = LayoutInflater.from(this); View customView = inflater.inflate(R.layout.custom_action_bair_tabs, null); customView.setLayoutPairams(new ViewGroup.LayoutPairams(ViewGroup.LayoutPairams.MATCH_PARENT, ViewGroup.LayoutPairams.MATCH_PARENT)); TextView tabCustom = (TextView) customView.findViewById(R.id.custom_action_bair_tab); tabCustom.setText(tabs[i].getTabTitle()); tabCustom.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL); tabCustom.setTypeface(TroviewApplication.getDefaultFontBold()); mActionBair.getTabAt(i).setCustomView(tabCustom); } // Now set up the button listeners for those icons mActionBair.getCustomView().findViewById(R.id.action_bair_friend_feed_button).setOnClickListener(this); mActionBair.getCustomView().findViewById(R.id.action_bair_me_button).setOnClickListener(this); mActionBair.getCustomView().findViewById(R.id.action_bair_neairby_button).setOnClickListener(this); mViewPager.setCurrentItem(previousTab); TroviewLocationManager manger = TroviewLocationManager.get(); if (!manger.isNetworkLocationEnabled() && !deniedLocationServices) { showLocationServicesDialog(); } if (AuthManager.get().isAuthenticated()) { mCurrentMode = Mode.NEWS_MODE; // <----- if I change this to GLOBE_MODE it doesn't crash } else { mCurrentMode = Mode.GLOBE_MODE; } validateView(); }  // We HAVE to read this value out before creating the layout, or onTabSelected will set it back to zero final ShairedPreferences prefs = getApplicationContext().getShairedPreferences( Const.Preferences.PREFS_FILE, Context.MODE_PRIVATE); boolean deniedLocationServices = prefs.getBoolean(Const.Preferences.LOCATION_SERVICES_DENIED, false); int previousTab = prefs.getInt(Const.Preferences.PREVIOUS_TAB, 0); setContentView(R.layout.main_browse); mFragmentManager = getSupportFragmentManager(); mActionBair = getActionBair(); mActionBair.setNavigationMode(ActionBair.NAVIGATION_MODE_TABS); // these three lines hide the 'Troview' logo mActionBair.setDisplayHomeAsUpEnabled(false); mActionBair.setDisplayUseLogoEnabled(false); mActionBair.setIcon(new ColorDrawable(android.R.color.black)); mActionBair.setCustomView(R.layout.action_bair_icons); mActionBair.setDisplayOptions(ActionBair.DISPLAY_SHOW_CUSTOM | ActionBair.DISPLAY_SHOW_HOME); final int numTabs = 8; TabbedBrowsePagerTab[] tabs = new TabbedBrowsePagerTab[numTabs]; tabs[mAllTabPosition] = buildAllTab(); tabs[mWhatsHotTabPosition] = buildWhatsHotTab(); tabs[mWhatsNewTabPosition] = buildWhatsNewTab(); tabs[mJumpToTabPosition] = buildJumpToTab(); tabs[mFoodTabPosition] = buildFoodTab(); tabs[mOutdoorTabPosition] = buildOutdoorTab(); tabs[mArtTabPosition] = buildArtTab(); tabs[mLatestTabPosition] = buildLatestTab(); mPagerAdapter = new TabbedBrowsePagerAdapter(this, tabs); mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager.setAdapter(mPagerAdapter); mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Oviewride public void onPageSelected(final int position) { try { mActionBair.setSelectedNavigationItem(position); } catch (final IllegalStateException e) { TroviewApplication.logError(TAG, "IllegalArgumentsException setting tab position in PageChangeListener"); } } }); // Build the actual tabs on the actionbair for (int i = 0; i < tabs.length; i++) { mActionBair.addTab(mActionBair.newTab() .setTabListener(this)); LayoutInflater inflater = LayoutInflater.from(this); View customView = inflater.inflate(R.layout.custom_action_bair_tabs, null); customView.setLayoutPairams(new ViewGroup.LayoutPairams(ViewGroup.LayoutPairams.MATCH_PARENT, ViewGroup.LayoutPairams.MATCH_PARENT)); TextView tabCustom = (TextView) customView.findViewById(R.id.custom_action_bair_tab); tabCustom.setText(tabs[i].getTabTitle()); tabCustom.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL); tabCustom.setTypeface(TroviewApplication.getDefaultFontBold()); mActionBair.getTabAt(i).setCustomView(tabCustom); } // Now set up the button listeners for those icons mActionBair.getCustomView().findViewById(R.id.action_bair_friend_feed_button).setOnClickListener(this); mActionBair.getCustomView().findViewById(R.id.action_bair_me_button).setOnClickListener(this); mActionBair.getCustomView().findViewById(R.id.action_bair_neairby_button).setOnClickListener(this); mViewPager.setCurrentItem(previousTab); TroviewLocationManager manger = TroviewLocationManager.get(); if (!manger.isNetworkLocationEnabled() && !deniedLocationServices) { showLocationServicesDialog(); } if (AuthManager.get().isAuthenticated()) { mCurrentMode = Mode.NEWS_MODE; // <----- if I change this to GLOBE_MODE it doesn't crash } else { mCurrentMode = Mode.GLOBE_MODE; } validateView(); }  // We HAVE to read this value out before creating the layout, or onTabSelected will set it back to zero final ShairedPreferences prefs = getApplicationContext().getShairedPreferences( Const.Preferences.PREFS_FILE, Context.MODE_PRIVATE); boolean deniedLocationServices = prefs.getBoolean(Const.Preferences.LOCATION_SERVICES_DENIED, false); int previousTab = prefs.getInt(Const.Preferences.PREVIOUS_TAB, 0); setContentView(R.layout.main_browse); mFragmentManager = getSupportFragmentManager(); mActionBair = getActionBair(); mActionBair.setNavigationMode(ActionBair.NAVIGATION_MODE_TABS); // these three lines hide the 'Troview' logo mActionBair.setDisplayHomeAsUpEnabled(false); mActionBair.setDisplayUseLogoEnabled(false); mActionBair.setIcon(new ColorDrawable(android.R.color.black)); mActionBair.setCustomView(R.layout.action_bair_icons); mActionBair.setDisplayOptions(ActionBair.DISPLAY_SHOW_CUSTOM | ActionBair.DISPLAY_SHOW_HOME); final int numTabs = 8; TabbedBrowsePagerTab[] tabs = new TabbedBrowsePagerTab[numTabs]; tabs[mAllTabPosition] = buildAllTab(); tabs[mWhatsHotTabPosition] = buildWhatsHotTab(); tabs[mWhatsNewTabPosition] = buildWhatsNewTab(); tabs[mJumpToTabPosition] = buildJumpToTab(); tabs[mFoodTabPosition] = buildFoodTab(); tabs[mOutdoorTabPosition] = buildOutdoorTab(); tabs[mArtTabPosition] = buildArtTab(); tabs[mLatestTabPosition] = buildLatestTab(); mPagerAdapter = new TabbedBrowsePagerAdapter(this, tabs); mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager.setAdapter(mPagerAdapter); mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Oviewride public void onPageSelected(final int position) { try { mActionBair.setSelectedNavigationItem(position); } catch (final IllegalStateException e) { TroviewApplication.logError(TAG, "IllegalArgumentsException setting tab position in PageChangeListener"); } } }); // Build the actual tabs on the actionbair for (int i = 0; i < tabs.length; i++) { mActionBair.addTab(mActionBair.newTab() .setTabListener(this)); LayoutInflater inflater = LayoutInflater.from(this); View customView = inflater.inflate(R.layout.custom_action_bair_tabs, null); customView.setLayoutPairams(new ViewGroup.LayoutPairams(ViewGroup.LayoutPairams.MATCH_PARENT, ViewGroup.LayoutPairams.MATCH_PARENT)); TextView tabCustom = (TextView) customView.findViewById(R.id.custom_action_bair_tab); tabCustom.setText(tabs[i].getTabTitle()); tabCustom.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL); tabCustom.setTypeface(TroviewApplication.getDefaultFontBold()); mActionBair.getTabAt(i).setCustomView(tabCustom); } // Now set up the button listeners for those icons mActionBair.getCustomView().findViewById(R.id.action_bair_friend_feed_button).setOnClickListener(this); mActionBair.getCustomView().findViewById(R.id.action_bair_me_button).setOnClickListener(this); mActionBair.getCustomView().findViewById(R.id.action_bair_neairby_button).setOnClickListener(this); mViewPager.setCurrentItem(previousTab); TroviewLocationManager manger = TroviewLocationManager.get(); if (!manger.isNetworkLocationEnabled() && !deniedLocationServices) { showLocationServicesDialog(); } if (AuthManager.get().isAuthenticated()) { mCurrentMode = Mode.NEWS_MODE; // <----- if I change this to GLOBE_MODE it doesn't crash } else { mCurrentMode = Mode.GLOBE_MODE; } validateView(); });  // We HAVE to read this value out before creating the layout, or onTabSelected will set it back to zero final ShairedPreferences prefs = getApplicationContext().getShairedPreferences( Const.Preferences.PREFS_FILE, Context.MODE_PRIVATE); boolean deniedLocationServices = prefs.getBoolean(Const.Preferences.LOCATION_SERVICES_DENIED, false); int previousTab = prefs.getInt(Const.Preferences.PREVIOUS_TAB, 0); setContentView(R.layout.main_browse); mFragmentManager = getSupportFragmentManager(); mActionBair = getActionBair(); mActionBair.setNavigationMode(ActionBair.NAVIGATION_MODE_TABS); // these three lines hide the 'Troview' logo mActionBair.setDisplayHomeAsUpEnabled(false); mActionBair.setDisplayUseLogoEnabled(false); mActionBair.setIcon(new ColorDrawable(android.R.color.black)); mActionBair.setCustomView(R.layout.action_bair_icons); mActionBair.setDisplayOptions(ActionBair.DISPLAY_SHOW_CUSTOM | ActionBair.DISPLAY_SHOW_HOME); final int numTabs = 8; TabbedBrowsePagerTab[] tabs = new TabbedBrowsePagerTab[numTabs]; tabs[mAllTabPosition] = buildAllTab(); tabs[mWhatsHotTabPosition] = buildWhatsHotTab(); tabs[mWhatsNewTabPosition] = buildWhatsNewTab(); tabs[mJumpToTabPosition] = buildJumpToTab(); tabs[mFoodTabPosition] = buildFoodTab(); tabs[mOutdoorTabPosition] = buildOutdoorTab(); tabs[mArtTabPosition] = buildArtTab(); tabs[mLatestTabPosition] = buildLatestTab(); mPagerAdapter = new TabbedBrowsePagerAdapter(this, tabs); mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager.setAdapter(mPagerAdapter); mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Oviewride public void onPageSelected(final int position) { try { mActionBair.setSelectedNavigationItem(position); } catch (final IllegalStateException e) { TroviewApplication.logError(TAG, "IllegalArgumentsException setting tab position in PageChangeListener"); } } }); // Build the actual tabs on the actionbair for (int i = 0; i < tabs.length; i++) { mActionBair.addTab(mActionBair.newTab() .setTabListener(this)); LayoutInflater inflater = LayoutInflater.from(this); View customView = inflater.inflate(R.layout.custom_action_bair_tabs, null); customView.setLayoutPairams(new ViewGroup.LayoutPairams(ViewGroup.LayoutPairams.MATCH_PARENT, ViewGroup.LayoutPairams.MATCH_PARENT)); TextView tabCustom = (TextView) customView.findViewById(R.id.custom_action_bair_tab); tabCustom.setText(tabs[i].getTabTitle()); tabCustom.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL); tabCustom.setTypeface(TroviewApplication.getDefaultFontBold()); mActionBair.getTabAt(i).setCustomView(tabCustom); } // Now set up the button listeners for those icons mActionBair.getCustomView().findViewById(R.id.action_bair_friend_feed_button).setOnClickListener(this); mActionBair.getCustomView().findViewById(R.id.action_bair_me_button).setOnClickListener(this); mActionBair.getCustomView().findViewById(R.id.action_bair_neairby_button).setOnClickListener(this); mViewPager.setCurrentItem(previousTab); TroviewLocationManager manger = TroviewLocationManager.get(); if (!manger.isNetworkLocationEnabled() && !deniedLocationServices) { showLocationServicesDialog(); } if (AuthManager.get().isAuthenticated()) { mCurrentMode = Mode.NEWS_MODE; // <----- if I change this to GLOBE_MODE it doesn't crash } else { mCurrentMode = Mode.GLOBE_MODE; } validateView(); }  // We HAVE to read this value out before creating the layout, or onTabSelected will set it back to zero final ShairedPreferences prefs = getApplicationContext().getShairedPreferences( Const.Preferences.PREFS_FILE, Context.MODE_PRIVATE); boolean deniedLocationServices = prefs.getBoolean(Const.Preferences.LOCATION_SERVICES_DENIED, false); int previousTab = prefs.getInt(Const.Preferences.PREVIOUS_TAB, 0); setContentView(R.layout.main_browse); mFragmentManager = getSupportFragmentManager(); mActionBair = getActionBair(); mActionBair.setNavigationMode(ActionBair.NAVIGATION_MODE_TABS); // these three lines hide the 'Troview' logo mActionBair.setDisplayHomeAsUpEnabled(false); mActionBair.setDisplayUseLogoEnabled(false); mActionBair.setIcon(new ColorDrawable(android.R.color.black)); mActionBair.setCustomView(R.layout.action_bair_icons); mActionBair.setDisplayOptions(ActionBair.DISPLAY_SHOW_CUSTOM | ActionBair.DISPLAY_SHOW_HOME); final int numTabs = 8; TabbedBrowsePagerTab[] tabs = new TabbedBrowsePagerTab[numTabs]; tabs[mAllTabPosition] = buildAllTab(); tabs[mWhatsHotTabPosition] = buildWhatsHotTab(); tabs[mWhatsNewTabPosition] = buildWhatsNewTab(); tabs[mJumpToTabPosition] = buildJumpToTab(); tabs[mFoodTabPosition] = buildFoodTab(); tabs[mOutdoorTabPosition] = buildOutdoorTab(); tabs[mArtTabPosition] = buildArtTab(); tabs[mLatestTabPosition] = buildLatestTab(); mPagerAdapter = new TabbedBrowsePagerAdapter(this, tabs); mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager.setAdapter(mPagerAdapter); mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Oviewride public void onPageSelected(final int position) { try { mActionBair.setSelectedNavigationItem(position); } catch (final IllegalStateException e) { TroviewApplication.logError(TAG, "IllegalArgumentsException setting tab position in PageChangeListener"); } } }); // Build the actual tabs on the actionbair for (int i = 0; i < tabs.length; i++) { mActionBair.addTab(mActionBair.newTab() .setTabListener(this)); LayoutInflater inflater = LayoutInflater.from(this); View customView = inflater.inflate(R.layout.custom_action_bair_tabs, null); customView.setLayoutPairams(new ViewGroup.LayoutPairams(ViewGroup.LayoutPairams.MATCH_PARENT, ViewGroup.LayoutPairams.MATCH_PARENT)); TextView tabCustom = (TextView) customView.findViewById(R.id.custom_action_bair_tab); tabCustom.setText(tabs[i].getTabTitle()); tabCustom.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL); tabCustom.setTypeface(TroviewApplication.getDefaultFontBold()); mActionBair.getTabAt(i).setCustomView(tabCustom); } // Now set up the button listeners for those icons mActionBair.getCustomView().findViewById(R.id.action_bair_friend_feed_button).setOnClickListener(this); mActionBair.getCustomView().findViewById(R.id.action_bair_me_button).setOnClickListener(this); mActionBair.getCustomView().findViewById(R.id.action_bair_neairby_button).setOnClickListener(this); mViewPager.setCurrentItem(previousTab); TroviewLocationManager manger = TroviewLocationManager.get(); if (!manger.isNetworkLocationEnabled() && !deniedLocationServices) { showLocationServicesDialog(); } if (AuthManager.get().isAuthenticated()) { mCurrentMode = Mode.NEWS_MODE; // <----- if I change this to GLOBE_MODE it doesn't crash } else { mCurrentMode = Mode.GLOBE_MODE; } validateView(); }  // We HAVE to read this value out before creating the layout, or onTabSelected will set it back to zero final ShairedPreferences prefs = getApplicationContext().getShairedPreferences( Const.Preferences.PREFS_FILE, Context.MODE_PRIVATE); boolean deniedLocationServices = prefs.getBoolean(Const.Preferences.LOCATION_SERVICES_DENIED, false); int previousTab = prefs.getInt(Const.Preferences.PREVIOUS_TAB, 0); setContentView(R.layout.main_browse); mFragmentManager = getSupportFragmentManager(); mActionBair = getActionBair(); mActionBair.setNavigationMode(ActionBair.NAVIGATION_MODE_TABS); // these three lines hide the 'Troview' logo mActionBair.setDisplayHomeAsUpEnabled(false); mActionBair.setDisplayUseLogoEnabled(false); mActionBair.setIcon(new ColorDrawable(android.R.color.black)); mActionBair.setCustomView(R.layout.action_bair_icons); mActionBair.setDisplayOptions(ActionBair.DISPLAY_SHOW_CUSTOM | ActionBair.DISPLAY_SHOW_HOME); final int numTabs = 8; TabbedBrowsePagerTab[] tabs = new TabbedBrowsePagerTab[numTabs]; tabs[mAllTabPosition] = buildAllTab(); tabs[mWhatsHotTabPosition] = buildWhatsHotTab(); tabs[mWhatsNewTabPosition] = buildWhatsNewTab(); tabs[mJumpToTabPosition] = buildJumpToTab(); tabs[mFoodTabPosition] = buildFoodTab(); tabs[mOutdoorTabPosition] = buildOutdoorTab(); tabs[mArtTabPosition] = buildArtTab(); tabs[mLatestTabPosition] = buildLatestTab(); mPagerAdapter = new TabbedBrowsePagerAdapter(this, tabs); mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager.setAdapter(mPagerAdapter); mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Oviewride public void onPageSelected(final int position) { try { mActionBair.setSelectedNavigationItem(position); } catch (final IllegalStateException e) { TroviewApplication.logError(TAG, "IllegalArgumentsException setting tab position in PageChangeListener"); } } }); // Build the actual tabs on the actionbair for (int i = 0; i < tabs.length; i++) { mActionBair.addTab(mActionBair.newTab() .setTabListener(this)); LayoutInflater inflater = LayoutInflater.from(this); View customView = inflater.inflate(R.layout.custom_action_bair_tabs, null); customView.setLayoutPairams(new ViewGroup.LayoutPairams(ViewGroup.LayoutPairams.MATCH_PARENT, ViewGroup.LayoutPairams.MATCH_PARENT)); TextView tabCustom = (TextView) customView.findViewById(R.id.custom_action_bair_tab); tabCustom.setText(tabs[i].getTabTitle()); tabCustom.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL); tabCustom.setTypeface(TroviewApplication.getDefaultFontBold()); mActionBair.getTabAt(i).setCustomView(tabCustom); } // Now set up the button listeners for those icons mActionBair.getCustomView().findViewById(R.id.action_bair_friend_feed_button).setOnClickListener(this); mActionBair.getCustomView().findViewById(R.id.action_bair_me_button).setOnClickListener(this); mActionBair.getCustomView().findViewById(R.id.action_bair_neairby_button).setOnClickListener(this); mViewPager.setCurrentItem(previousTab); TroviewLocationManager manger = TroviewLocationManager.get(); if (!manger.isNetworkLocationEnabled() && !deniedLocationServices) { showLocationServicesDialog(); } if (AuthManager.get().isAuthenticated()) { mCurrentMode = Mode.NEWS_MODE; // <----- if I change this to GLOBE_MODE it doesn't crash } else { mCurrentMode = Mode.GLOBE_MODE; } validateView(); }  // We HAVE to read this value out before creating the layout, or onTabSelected will set it back to zero final ShairedPreferences prefs = getApplicationContext().getShairedPreferences( Const.Preferences.PREFS_FILE, Context.MODE_PRIVATE); boolean deniedLocationServices = prefs.getBoolean(Const.Preferences.LOCATION_SERVICES_DENIED, false); int previousTab = prefs.getInt(Const.Preferences.PREVIOUS_TAB, 0); setContentView(R.layout.main_browse); mFragmentManager = getSupportFragmentManager(); mActionBair = getActionBair(); mActionBair.setNavigationMode(ActionBair.NAVIGATION_MODE_TABS); // these three lines hide the 'Troview' logo mActionBair.setDisplayHomeAsUpEnabled(false); mActionBair.setDisplayUseLogoEnabled(false); mActionBair.setIcon(new ColorDrawable(android.R.color.black)); mActionBair.setCustomView(R.layout.action_bair_icons); mActionBair.setDisplayOptions(ActionBair.DISPLAY_SHOW_CUSTOM | ActionBair.DISPLAY_SHOW_HOME); final int numTabs = 8; TabbedBrowsePagerTab[] tabs = new TabbedBrowsePagerTab[numTabs]; tabs[mAllTabPosition] = buildAllTab(); tabs[mWhatsHotTabPosition] = buildWhatsHotTab(); tabs[mWhatsNewTabPosition] = buildWhatsNewTab(); tabs[mJumpToTabPosition] = buildJumpToTab(); tabs[mFoodTabPosition] = buildFoodTab(); tabs[mOutdoorTabPosition] = buildOutdoorTab(); tabs[mArtTabPosition] = buildArtTab(); tabs[mLatestTabPosition] = buildLatestTab(); mPagerAdapter = new TabbedBrowsePagerAdapter(this, tabs); mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager.setAdapter(mPagerAdapter); mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Oviewride public void onPageSelected(final int position) { try { mActionBair.setSelectedNavigationItem(position); } catch (final IllegalStateException e) { TroviewApplication.logError(TAG, "IllegalArgumentsException setting tab position in PageChangeListener"); } } }); // Build the actual tabs on the actionbair for (int i = 0; i < tabs.length; i++) { mActionBair.addTab(mActionBair.newTab() .setTabListener(this)); LayoutInflater inflater = LayoutInflater.from(this); View customView = inflater.inflate(R.layout.custom_action_bair_tabs, null); customView.setLayoutPairams(new ViewGroup.LayoutPairams(ViewGroup.LayoutPairams.MATCH_PARENT, ViewGroup.LayoutPairams.MATCH_PARENT)); TextView tabCustom = (TextView) customView.findViewById(R.id.custom_action_bair_tab); tabCustom.setText(tabs[i].getTabTitle()); tabCustom.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL); tabCustom.setTypeface(TroviewApplication.getDefaultFontBold()); mActionBair.getTabAt(i).setCustomView(tabCustom); } // Now set up the button listeners for those icons mActionBair.getCustomView().findViewById(R.id.action_bair_friend_feed_button).setOnClickListener(this); mActionBair.getCustomView().findViewById(R.id.action_bair_me_button).setOnClickListener(this); mActionBair.getCustomView().findViewById(R.id.action_bair_neairby_button).setOnClickListener(this); mViewPager.setCurrentItem(previousTab); TroviewLocationManager manger = TroviewLocationManager.get(); if (!manger.isNetworkLocationEnabled() && !deniedLocationServices) { showLocationServicesDialog(); } if (AuthManager.get().isAuthenticated()) { mCurrentMode = Mode.NEWS_MODE; // <----- if I change this to GLOBE_MODE it doesn't crash } else { mCurrentMode = Mode.GLOBE_MODE; } validateView(); 

    Aqui está o layout main_browse.xml:

     <?xml viewsion="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="fill_pairent" android:layout_width="fill_pairent" > <android.support.v4.view.ViewPager android:id="@+id/pager" android:layout_width="match_pairent" android:layout_height="match_pairent" /> <Button android:id="@+id/main_camera_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignPairentBottom="true" android:layout_alignPairentRight="true" android:layout_mairginBottom="15dp" android:layout_mairginRight="15dp" android:background="@drawable/camera_floating" /> </RelativeLayout> 

    Aqui está a function setHighlightedIconButton:

     private void setHighlightedIconButton() { ImageButton button; View iconContainer = mActionBair.getCustomView(); PaintDrawable selectedBackground = new PaintDrawable(getResources().getColor(R.color.troview_selected_icon_background)); button = (ImageButton) iconContainer.findViewById(R.id.action_bair_friend_feed_button); if (mCurrentMode == Mode.NEWS_MODE) { button.setBackgroundDrawable(selectedBackground); button.setClickable(false); } else { button.setBackgroundDrawable(null); button.setClickable(true); } button = (ImageButton) iconContainer.findViewById(R.id.action_bair_neairby_button); if (mCurrentMode == Mode.GLOBE_MODE) { button.setBackgroundDrawable(selectedBackground); button.setClickable(false); } else { button.setBackgroundDrawable(null); button.setClickable(true); } button = (ImageButton) iconContainer.findViewById(R.id.action_bair_me_button); if (mCurrentMode == Mode.PROFILE_MODE) { button.setBackgroundDrawable(selectedBackground); button.setClickable(false); } else { button.setBackgroundDrawable(null); button.setClickable(true); } } } private void setHighlightedIconButton() { ImageButton button; View iconContainer = mActionBair.getCustomView(); PaintDrawable selectedBackground = new PaintDrawable(getResources().getColor(R.color.troview_selected_icon_background)); button = (ImageButton) iconContainer.findViewById(R.id.action_bair_friend_feed_button); if (mCurrentMode == Mode.NEWS_MODE) { button.setBackgroundDrawable(selectedBackground); button.setClickable(false); } else { button.setBackgroundDrawable(null); button.setClickable(true); } button = (ImageButton) iconContainer.findViewById(R.id.action_bair_neairby_button); if (mCurrentMode == Mode.GLOBE_MODE) { button.setBackgroundDrawable(selectedBackground); button.setClickable(false); } else { button.setBackgroundDrawable(null); button.setClickable(true); } button = (ImageButton) iconContainer.findViewById(R.id.action_bair_me_button); if (mCurrentMode == Mode.PROFILE_MODE) { button.setBackgroundDrawable(selectedBackground); button.setClickable(false); } else { button.setBackgroundDrawable(null); button.setClickable(true); } } } private void setHighlightedIconButton() { ImageButton button; View iconContainer = mActionBair.getCustomView(); PaintDrawable selectedBackground = new PaintDrawable(getResources().getColor(R.color.troview_selected_icon_background)); button = (ImageButton) iconContainer.findViewById(R.id.action_bair_friend_feed_button); if (mCurrentMode == Mode.NEWS_MODE) { button.setBackgroundDrawable(selectedBackground); button.setClickable(false); } else { button.setBackgroundDrawable(null); button.setClickable(true); } button = (ImageButton) iconContainer.findViewById(R.id.action_bair_neairby_button); if (mCurrentMode == Mode.GLOBE_MODE) { button.setBackgroundDrawable(selectedBackground); button.setClickable(false); } else { button.setBackgroundDrawable(null); button.setClickable(true); } button = (ImageButton) iconContainer.findViewById(R.id.action_bair_me_button); if (mCurrentMode == Mode.PROFILE_MODE) { button.setBackgroundDrawable(selectedBackground); button.setClickable(false); } else { button.setBackgroundDrawable(null); button.setClickable(true); } } } private void setHighlightedIconButton() { ImageButton button; View iconContainer = mActionBair.getCustomView(); PaintDrawable selectedBackground = new PaintDrawable(getResources().getColor(R.color.troview_selected_icon_background)); button = (ImageButton) iconContainer.findViewById(R.id.action_bair_friend_feed_button); if (mCurrentMode == Mode.NEWS_MODE) { button.setBackgroundDrawable(selectedBackground); button.setClickable(false); } else { button.setBackgroundDrawable(null); button.setClickable(true); } button = (ImageButton) iconContainer.findViewById(R.id.action_bair_neairby_button); if (mCurrentMode == Mode.GLOBE_MODE) { button.setBackgroundDrawable(selectedBackground); button.setClickable(false); } else { button.setBackgroundDrawable(null); button.setClickable(true); } button = (ImageButton) iconContainer.findViewById(R.id.action_bair_me_button); if (mCurrentMode == Mode.PROFILE_MODE) { button.setBackgroundDrawable(selectedBackground); button.setClickable(false); } else { button.setBackgroundDrawable(null); button.setClickable(true); } } 

    E esta é a function validateView () que o chama:

     /** * Handles transitions between different fragments by checking the current mode and authentication state. * This function can handle being called multiple times, and will always try to do the least work possible * each time. */ private void validateView() { invalidateOptionsMenu(); setHighlightedIconButton(); boolean authenticated = AuthManager.get().isAuthenticated(); switch(mCurrentMode) { case GLOBE_MODE: // Note - we don't record a screen here because the tabs will do that removeMeFragment(); removeNewsFragment(); removeOnboairdingFragment(); mViewPager.setVisibility(View.VISIBLE); mActionBair.setNavigationMode(ActionBair.NAVIGATION_MODE_TABS); mPagerAdapter.madeVisible(); break; case NEWS_MODE: if (mPreviousTabPosition == mJumpToTabPosition) { InputMethodManager imm = (InputMethodManager) getSystemService( Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(mViewPager.getWindowToken(), 0); } recordScreen(getCurrentModeTrackingString(), this); removeMeFragment(); removeOnboairdingFragment(); if (mNewsFeedFragment == null) { mNewsFeedFragment = DiscoviewyListFragment.newNewsFeedInstance(); mFragmentManager.beginTransaction().add(android.R.id.content, mNewsFeedFragment).commit(); } mActionBair.setNavigationMode(ActionBair.NAVIGATION_MODE_STANDARD); mViewPager.setVisibility(View.GONE); break; case PROFILE_MODE: if (mPreviousTabPosition == mJumpToTabPosition) { InputMethodManager imm = (InputMethodManager) getSystemService( Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(mViewPager.getWindowToken(), 0); } if (authenticated) { recordScreen(getCurrentModeTrackingString(), this); removeNewsFragment(); removeOnboairdingFragment(); if (mProfileFragment == null) { mProfileFragment = UserDetailFragment.newMeInstance(); mFragmentManager.beginTransaction().add(android.R.id.content, mProfileFragment).commit(); } } else { recordScreen(getCurrentModeTrackingString() + "/onboairding", this); removeMeFragment(); removeNewsFragment(); if (mOnboairdingFragment == null) { removeOnboairdingFragment(); mOnboairdingFragment = new OnboairdingFragment(); mFragmentManager.beginTransaction().add(android.R.id.content, mOnboairdingFragment).commit(); } } mViewPager.setVisibility(View.GONE); break; default: TroviewApplication.logError(TAG, "Invalid mode!"); } } * / /** * Handles transitions between different fragments by checking the current mode and authentication state. * This function can handle being called multiple times, and will always try to do the least work possible * each time. */ private void validateView() { invalidateOptionsMenu(); setHighlightedIconButton(); boolean authenticated = AuthManager.get().isAuthenticated(); switch(mCurrentMode) { case GLOBE_MODE: // Note - we don't record a screen here because the tabs will do that removeMeFragment(); removeNewsFragment(); removeOnboairdingFragment(); mViewPager.setVisibility(View.VISIBLE); mActionBair.setNavigationMode(ActionBair.NAVIGATION_MODE_TABS); mPagerAdapter.madeVisible(); break; case NEWS_MODE: if (mPreviousTabPosition == mJumpToTabPosition) { InputMethodManager imm = (InputMethodManager) getSystemService( Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(mViewPager.getWindowToken(), 0); } recordScreen(getCurrentModeTrackingString(), this); removeMeFragment(); removeOnboairdingFragment(); if (mNewsFeedFragment == null) { mNewsFeedFragment = DiscoviewyListFragment.newNewsFeedInstance(); mFragmentManager.beginTransaction().add(android.R.id.content, mNewsFeedFragment).commit(); } mActionBair.setNavigationMode(ActionBair.NAVIGATION_MODE_STANDARD); mViewPager.setVisibility(View.GONE); break; case PROFILE_MODE: if (mPreviousTabPosition == mJumpToTabPosition) { InputMethodManager imm = (InputMethodManager) getSystemService( Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(mViewPager.getWindowToken(), 0); } if (authenticated) { recordScreen(getCurrentModeTrackingString(), this); removeNewsFragment(); removeOnboairdingFragment(); if (mProfileFragment == null) { mProfileFragment = UserDetailFragment.newMeInstance(); mFragmentManager.beginTransaction().add(android.R.id.content, mProfileFragment).commit(); } } else { recordScreen(getCurrentModeTrackingString() + "/onboairding", this); removeMeFragment(); removeNewsFragment(); if (mOnboairdingFragment == null) { removeOnboairdingFragment(); mOnboairdingFragment = new OnboairdingFragment(); mFragmentManager.beginTransaction().add(android.R.id.content, mOnboairdingFragment).commit(); } } mViewPager.setVisibility(View.GONE); break; default: TroviewApplication.logError(TAG, "Invalid mode!"); } } } /** * Handles transitions between different fragments by checking the current mode and authentication state. * This function can handle being called multiple times, and will always try to do the least work possible * each time. */ private void validateView() { invalidateOptionsMenu(); setHighlightedIconButton(); boolean authenticated = AuthManager.get().isAuthenticated(); switch(mCurrentMode) { case GLOBE_MODE: // Note - we don't record a screen here because the tabs will do that removeMeFragment(); removeNewsFragment(); removeOnboairdingFragment(); mViewPager.setVisibility(View.VISIBLE); mActionBair.setNavigationMode(ActionBair.NAVIGATION_MODE_TABS); mPagerAdapter.madeVisible(); break; case NEWS_MODE: if (mPreviousTabPosition == mJumpToTabPosition) { InputMethodManager imm = (InputMethodManager) getSystemService( Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(mViewPager.getWindowToken(), 0); } recordScreen(getCurrentModeTrackingString(), this); removeMeFragment(); removeOnboairdingFragment(); if (mNewsFeedFragment == null) { mNewsFeedFragment = DiscoviewyListFragment.newNewsFeedInstance(); mFragmentManager.beginTransaction().add(android.R.id.content, mNewsFeedFragment).commit(); } mActionBair.setNavigationMode(ActionBair.NAVIGATION_MODE_STANDARD); mViewPager.setVisibility(View.GONE); break; case PROFILE_MODE: if (mPreviousTabPosition == mJumpToTabPosition) { InputMethodManager imm = (InputMethodManager) getSystemService( Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(mViewPager.getWindowToken(), 0); } if (authenticated) { recordScreen(getCurrentModeTrackingString(), this); removeNewsFragment(); removeOnboairdingFragment(); if (mProfileFragment == null) { mProfileFragment = UserDetailFragment.newMeInstance(); mFragmentManager.beginTransaction().add(android.R.id.content, mProfileFragment).commit(); } } else { recordScreen(getCurrentModeTrackingString() + "/onboairding", this); removeMeFragment(); removeNewsFragment(); if (mOnboairdingFragment == null) { removeOnboairdingFragment(); mOnboairdingFragment = new OnboairdingFragment(); mFragmentManager.beginTransaction().add(android.R.id.content, mOnboairdingFragment).commit(); } } mViewPager.setVisibility(View.GONE); break; default: TroviewApplication.logError(TAG, "Invalid mode!"); } } } /** * Handles transitions between different fragments by checking the current mode and authentication state. * This function can handle being called multiple times, and will always try to do the least work possible * each time. */ private void validateView() { invalidateOptionsMenu(); setHighlightedIconButton(); boolean authenticated = AuthManager.get().isAuthenticated(); switch(mCurrentMode) { case GLOBE_MODE: // Note - we don't record a screen here because the tabs will do that removeMeFragment(); removeNewsFragment(); removeOnboairdingFragment(); mViewPager.setVisibility(View.VISIBLE); mActionBair.setNavigationMode(ActionBair.NAVIGATION_MODE_TABS); mPagerAdapter.madeVisible(); break; case NEWS_MODE: if (mPreviousTabPosition == mJumpToTabPosition) { InputMethodManager imm = (InputMethodManager) getSystemService( Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(mViewPager.getWindowToken(), 0); } recordScreen(getCurrentModeTrackingString(), this); removeMeFragment(); removeOnboairdingFragment(); if (mNewsFeedFragment == null) { mNewsFeedFragment = DiscoviewyListFragment.newNewsFeedInstance(); mFragmentManager.beginTransaction().add(android.R.id.content, mNewsFeedFragment).commit(); } mActionBair.setNavigationMode(ActionBair.NAVIGATION_MODE_STANDARD); mViewPager.setVisibility(View.GONE); break; case PROFILE_MODE: if (mPreviousTabPosition == mJumpToTabPosition) { InputMethodManager imm = (InputMethodManager) getSystemService( Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(mViewPager.getWindowToken(), 0); } if (authenticated) { recordScreen(getCurrentModeTrackingString(), this); removeNewsFragment(); removeOnboairdingFragment(); if (mProfileFragment == null) { mProfileFragment = UserDetailFragment.newMeInstance(); mFragmentManager.beginTransaction().add(android.R.id.content, mProfileFragment).commit(); } } else { recordScreen(getCurrentModeTrackingString() + "/onboairding", this); removeMeFragment(); removeNewsFragment(); if (mOnboairdingFragment == null) { removeOnboairdingFragment(); mOnboairdingFragment = new OnboairdingFragment(); mFragmentManager.beginTransaction().add(android.R.id.content, mOnboairdingFragment).commit(); } } mViewPager.setVisibility(View.GONE); break; default: TroviewApplication.logError(TAG, "Invalid mode!"); } } } /** * Handles transitions between different fragments by checking the current mode and authentication state. * This function can handle being called multiple times, and will always try to do the least work possible * each time. */ private void validateView() { invalidateOptionsMenu(); setHighlightedIconButton(); boolean authenticated = AuthManager.get().isAuthenticated(); switch(mCurrentMode) { case GLOBE_MODE: // Note - we don't record a screen here because the tabs will do that removeMeFragment(); removeNewsFragment(); removeOnboairdingFragment(); mViewPager.setVisibility(View.VISIBLE); mActionBair.setNavigationMode(ActionBair.NAVIGATION_MODE_TABS); mPagerAdapter.madeVisible(); break; case NEWS_MODE: if (mPreviousTabPosition == mJumpToTabPosition) { InputMethodManager imm = (InputMethodManager) getSystemService( Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(mViewPager.getWindowToken(), 0); } recordScreen(getCurrentModeTrackingString(), this); removeMeFragment(); removeOnboairdingFragment(); if (mNewsFeedFragment == null) { mNewsFeedFragment = DiscoviewyListFragment.newNewsFeedInstance(); mFragmentManager.beginTransaction().add(android.R.id.content, mNewsFeedFragment).commit(); } mActionBair.setNavigationMode(ActionBair.NAVIGATION_MODE_STANDARD); mViewPager.setVisibility(View.GONE); break; case PROFILE_MODE: if (mPreviousTabPosition == mJumpToTabPosition) { InputMethodManager imm = (InputMethodManager) getSystemService( Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(mViewPager.getWindowToken(), 0); } if (authenticated) { recordScreen(getCurrentModeTrackingString(), this); removeNewsFragment(); removeOnboairdingFragment(); if (mProfileFragment == null) { mProfileFragment = UserDetailFragment.newMeInstance(); mFragmentManager.beginTransaction().add(android.R.id.content, mProfileFragment).commit(); } } else { recordScreen(getCurrentModeTrackingString() + "/onboairding", this); removeMeFragment(); removeNewsFragment(); if (mOnboairdingFragment == null) { removeOnboairdingFragment(); mOnboairdingFragment = new OnboairdingFragment(); mFragmentManager.beginTransaction().add(android.R.id.content, mOnboairdingFragment).commit(); } } mViewPager.setVisibility(View.GONE); break; default: TroviewApplication.logError(TAG, "Invalid mode!"); } } } /** * Handles transitions between different fragments by checking the current mode and authentication state. * This function can handle being called multiple times, and will always try to do the least work possible * each time. */ private void validateView() { invalidateOptionsMenu(); setHighlightedIconButton(); boolean authenticated = AuthManager.get().isAuthenticated(); switch(mCurrentMode) { case GLOBE_MODE: // Note - we don't record a screen here because the tabs will do that removeMeFragment(); removeNewsFragment(); removeOnboairdingFragment(); mViewPager.setVisibility(View.VISIBLE); mActionBair.setNavigationMode(ActionBair.NAVIGATION_MODE_TABS); mPagerAdapter.madeVisible(); break; case NEWS_MODE: if (mPreviousTabPosition == mJumpToTabPosition) { InputMethodManager imm = (InputMethodManager) getSystemService( Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(mViewPager.getWindowToken(), 0); } recordScreen(getCurrentModeTrackingString(), this); removeMeFragment(); removeOnboairdingFragment(); if (mNewsFeedFragment == null) { mNewsFeedFragment = DiscoviewyListFragment.newNewsFeedInstance(); mFragmentManager.beginTransaction().add(android.R.id.content, mNewsFeedFragment).commit(); } mActionBair.setNavigationMode(ActionBair.NAVIGATION_MODE_STANDARD); mViewPager.setVisibility(View.GONE); break; case PROFILE_MODE: if (mPreviousTabPosition == mJumpToTabPosition) { InputMethodManager imm = (InputMethodManager) getSystemService( Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(mViewPager.getWindowToken(), 0); } if (authenticated) { recordScreen(getCurrentModeTrackingString(), this); removeNewsFragment(); removeOnboairdingFragment(); if (mProfileFragment == null) { mProfileFragment = UserDetailFragment.newMeInstance(); mFragmentManager.beginTransaction().add(android.R.id.content, mProfileFragment).commit(); } } else { recordScreen(getCurrentModeTrackingString() + "/onboairding", this); removeMeFragment(); removeNewsFragment(); if (mOnboairdingFragment == null) { removeOnboairdingFragment(); mOnboairdingFragment = new OnboairdingFragment(); mFragmentManager.beginTransaction().add(android.R.id.content, mOnboairdingFragment).commit(); } } mViewPager.setVisibility(View.GONE); break; default: TroviewApplication.logError(TAG, "Invalid mode!"); } } } /** * Handles transitions between different fragments by checking the current mode and authentication state. * This function can handle being called multiple times, and will always try to do the least work possible * each time. */ private void validateView() { invalidateOptionsMenu(); setHighlightedIconButton(); boolean authenticated = AuthManager.get().isAuthenticated(); switch(mCurrentMode) { case GLOBE_MODE: // Note - we don't record a screen here because the tabs will do that removeMeFragment(); removeNewsFragment(); removeOnboairdingFragment(); mViewPager.setVisibility(View.VISIBLE); mActionBair.setNavigationMode(ActionBair.NAVIGATION_MODE_TABS); mPagerAdapter.madeVisible(); break; case NEWS_MODE: if (mPreviousTabPosition == mJumpToTabPosition) { InputMethodManager imm = (InputMethodManager) getSystemService( Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(mViewPager.getWindowToken(), 0); } recordScreen(getCurrentModeTrackingString(), this); removeMeFragment(); removeOnboairdingFragment(); if (mNewsFeedFragment == null) { mNewsFeedFragment = DiscoviewyListFragment.newNewsFeedInstance(); mFragmentManager.beginTransaction().add(android.R.id.content, mNewsFeedFragment).commit(); } mActionBair.setNavigationMode(ActionBair.NAVIGATION_MODE_STANDARD); mViewPager.setVisibility(View.GONE); break; case PROFILE_MODE: if (mPreviousTabPosition == mJumpToTabPosition) { InputMethodManager imm = (InputMethodManager) getSystemService( Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(mViewPager.getWindowToken(), 0); } if (authenticated) { recordScreen(getCurrentModeTrackingString(), this); removeNewsFragment(); removeOnboairdingFragment(); if (mProfileFragment == null) { mProfileFragment = UserDetailFragment.newMeInstance(); mFragmentManager.beginTransaction().add(android.R.id.content, mProfileFragment).commit(); } } else { recordScreen(getCurrentModeTrackingString() + "/onboairding", this); removeMeFragment(); removeNewsFragment(); if (mOnboairdingFragment == null) { removeOnboairdingFragment(); mOnboairdingFragment = new OnboairdingFragment(); mFragmentManager.beginTransaction().add(android.R.id.content, mOnboairdingFragment).commit(); } } mViewPager.setVisibility(View.GONE); break; default: TroviewApplication.logError(TAG, "Invalid mode!"); } } } /** * Handles transitions between different fragments by checking the current mode and authentication state. * This function can handle being called multiple times, and will always try to do the least work possible * each time. */ private void validateView() { invalidateOptionsMenu(); setHighlightedIconButton(); boolean authenticated = AuthManager.get().isAuthenticated(); switch(mCurrentMode) { case GLOBE_MODE: // Note - we don't record a screen here because the tabs will do that removeMeFragment(); removeNewsFragment(); removeOnboairdingFragment(); mViewPager.setVisibility(View.VISIBLE); mActionBair.setNavigationMode(ActionBair.NAVIGATION_MODE_TABS); mPagerAdapter.madeVisible(); break; case NEWS_MODE: if (mPreviousTabPosition == mJumpToTabPosition) { InputMethodManager imm = (InputMethodManager) getSystemService( Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(mViewPager.getWindowToken(), 0); } recordScreen(getCurrentModeTrackingString(), this); removeMeFragment(); removeOnboairdingFragment(); if (mNewsFeedFragment == null) { mNewsFeedFragment = DiscoviewyListFragment.newNewsFeedInstance(); mFragmentManager.beginTransaction().add(android.R.id.content, mNewsFeedFragment).commit(); } mActionBair.setNavigationMode(ActionBair.NAVIGATION_MODE_STANDARD); mViewPager.setVisibility(View.GONE); break; case PROFILE_MODE: if (mPreviousTabPosition == mJumpToTabPosition) { InputMethodManager imm = (InputMethodManager) getSystemService( Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(mViewPager.getWindowToken(), 0); } if (authenticated) { recordScreen(getCurrentModeTrackingString(), this); removeNewsFragment(); removeOnboairdingFragment(); if (mProfileFragment == null) { mProfileFragment = UserDetailFragment.newMeInstance(); mFragmentManager.beginTransaction().add(android.R.id.content, mProfileFragment).commit(); } } else { recordScreen(getCurrentModeTrackingString() + "/onboairding", this); removeMeFragment(); removeNewsFragment(); if (mOnboairdingFragment == null) { removeOnboairdingFragment(); mOnboairdingFragment = new OnboairdingFragment(); mFragmentManager.beginTransaction().add(android.R.id.content, mOnboairdingFragment).commit(); } } mViewPager.setVisibility(View.GONE); break; default: TroviewApplication.logError(TAG, "Invalid mode!"); } } } /** * Handles transitions between different fragments by checking the current mode and authentication state. * This function can handle being called multiple times, and will always try to do the least work possible * each time. */ private void validateView() { invalidateOptionsMenu(); setHighlightedIconButton(); boolean authenticated = AuthManager.get().isAuthenticated(); switch(mCurrentMode) { case GLOBE_MODE: // Note - we don't record a screen here because the tabs will do that removeMeFragment(); removeNewsFragment(); removeOnboairdingFragment(); mViewPager.setVisibility(View.VISIBLE); mActionBair.setNavigationMode(ActionBair.NAVIGATION_MODE_TABS); mPagerAdapter.madeVisible(); break; case NEWS_MODE: if (mPreviousTabPosition == mJumpToTabPosition) { InputMethodManager imm = (InputMethodManager) getSystemService( Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(mViewPager.getWindowToken(), 0); } recordScreen(getCurrentModeTrackingString(), this); removeMeFragment(); removeOnboairdingFragment(); if (mNewsFeedFragment == null) { mNewsFeedFragment = DiscoviewyListFragment.newNewsFeedInstance(); mFragmentManager.beginTransaction().add(android.R.id.content, mNewsFeedFragment).commit(); } mActionBair.setNavigationMode(ActionBair.NAVIGATION_MODE_STANDARD); mViewPager.setVisibility(View.GONE); break; case PROFILE_MODE: if (mPreviousTabPosition == mJumpToTabPosition) { InputMethodManager imm = (InputMethodManager) getSystemService( Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(mViewPager.getWindowToken(), 0); } if (authenticated) { recordScreen(getCurrentModeTrackingString(), this); removeNewsFragment(); removeOnboairdingFragment(); if (mProfileFragment == null) { mProfileFragment = UserDetailFragment.newMeInstance(); mFragmentManager.beginTransaction().add(android.R.id.content, mProfileFragment).commit(); } } else { recordScreen(getCurrentModeTrackingString() + "/onboairding", this); removeMeFragment(); removeNewsFragment(); if (mOnboairdingFragment == null) { removeOnboairdingFragment(); mOnboairdingFragment = new OnboairdingFragment(); mFragmentManager.beginTransaction().add(android.R.id.content, mOnboairdingFragment).commit(); } } mViewPager.setVisibility(View.GONE); break; default: TroviewApplication.logError(TAG, "Invalid mode!"); } } 

    Aqui está o onCreateOptionsMenu paira a atividade principal:

     public boolean onCreateOptionsMenu(final Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.menu, menu); if (!AuthManager.get().isAuthenticated()) { MenuItem item = menu.findItem(R.id.menu_notifications); if (item != null) { item.setVisible(false); } item = menu.findItem(R.id.menu_recommended_users); if (item != null) { item.setVisible(false); } } return true; } } public boolean onCreateOptionsMenu(final Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.menu, menu); if (!AuthManager.get().isAuthenticated()) { MenuItem item = menu.findItem(R.id.menu_notifications); if (item != null) { item.setVisible(false); } item = menu.findItem(R.id.menu_recommended_users); if (item != null) { item.setVisible(false); } } return true; } } public boolean onCreateOptionsMenu(final Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.menu, menu); if (!AuthManager.get().isAuthenticated()) { MenuItem item = menu.findItem(R.id.menu_notifications); if (item != null) { item.setVisible(false); } item = menu.findItem(R.id.menu_recommended_users); if (item != null) { item.setVisible(false); } } return true; } } public boolean onCreateOptionsMenu(final Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.menu, menu); if (!AuthManager.get().isAuthenticated()) { MenuItem item = menu.findItem(R.id.menu_notifications); if (item != null) { item.setVisible(false); } item = menu.findItem(R.id.menu_recommended_users); if (item != null) { item.setVisible(false); } } return true; } retornair viewdadeiro; public boolean onCreateOptionsMenu(final Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.menu, menu); if (!AuthManager.get().isAuthenticated()) { MenuItem item = menu.findItem(R.id.menu_notifications); if (item != null) { item.setVisible(false); } item = menu.findItem(R.id.menu_recommended_users); if (item != null) { item.setVisible(false); } } return true; } 

    Esta é a pairte da function FrameLayout.onMeasure() que faz pairte do código-fonte da API do Android 19, onde está crashndo:

     @Oviewride protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int count = getChildCount(); <-- this is returning 2 final boolean measureMatchPairentChildren = MeasureSpec.getMode(widthMeasureSpec) != MeasureSpec.EXACTLY || MeasureSpec.getMode(heightMeasureSpec) != MeasureSpec.EXACTLY; mMatchPairentChildren.cleair(); int maxHeight = 0; int maxWidth = 0; int childState = 0; for (int i = 0; i < count; i++) { final View child = getChildAt(i); if (mMeasureAllChildren || child.getVisibility() != GONE) { <-- crash happens here measureChildWithMairgins(child, widthMeasureSpec, 0, heightMeasureSpec, 0); final LayoutPairams lp = (LayoutPairams) child.getLayoutPairams(); maxWidth = Math.max(maxWidth, child.getMeasuredWidth() + lp.leftMairgin + lp.rightMairgin); maxHeight = Math.max(maxHeight, child.getMeasuredHeight() + lp.topMairgin + lp.bottomMairgin); childState = combineMeasuredStates(childState, child.getMeasuredState()); if (measureMatchPairentChildren) { if (lp.width == LayoutPairams.MATCH_PARENT || lp.height == LayoutPairams.MATCH_PARENT) { mMatchPairentChildren.add(child); } } } } } @Oviewride protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int count = getChildCount(); <-- this is returning 2 final boolean measureMatchPairentChildren = MeasureSpec.getMode(widthMeasureSpec) != MeasureSpec.EXACTLY || MeasureSpec.getMode(heightMeasureSpec) != MeasureSpec.EXACTLY; mMatchPairentChildren.cleair(); int maxHeight = 0; int maxWidth = 0; int childState = 0; for (int i = 0; i < count; i++) { final View child = getChildAt(i); if (mMeasureAllChildren || child.getVisibility() != GONE) { <-- crash happens here measureChildWithMairgins(child, widthMeasureSpec, 0, heightMeasureSpec, 0); final LayoutPairams lp = (LayoutPairams) child.getLayoutPairams(); maxWidth = Math.max(maxWidth, child.getMeasuredWidth() + lp.leftMairgin + lp.rightMairgin); maxHeight = Math.max(maxHeight, child.getMeasuredHeight() + lp.topMairgin + lp.bottomMairgin); childState = combineMeasuredStates(childState, child.getMeasuredState()); if (measureMatchPairentChildren) { if (lp.width == LayoutPairams.MATCH_PARENT || lp.height == LayoutPairams.MATCH_PARENT) { mMatchPairentChildren.add(child); } } } } } @Oviewride protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int count = getChildCount(); <-- this is returning 2 final boolean measureMatchPairentChildren = MeasureSpec.getMode(widthMeasureSpec) != MeasureSpec.EXACTLY || MeasureSpec.getMode(heightMeasureSpec) != MeasureSpec.EXACTLY; mMatchPairentChildren.cleair(); int maxHeight = 0; int maxWidth = 0; int childState = 0; for (int i = 0; i < count; i++) { final View child = getChildAt(i); if (mMeasureAllChildren || child.getVisibility() != GONE) { <-- crash happens here measureChildWithMairgins(child, widthMeasureSpec, 0, heightMeasureSpec, 0); final LayoutPairams lp = (LayoutPairams) child.getLayoutPairams(); maxWidth = Math.max(maxWidth, child.getMeasuredWidth() + lp.leftMairgin + lp.rightMairgin); maxHeight = Math.max(maxHeight, child.getMeasuredHeight() + lp.topMairgin + lp.bottomMairgin); childState = combineMeasuredStates(childState, child.getMeasuredState()); if (measureMatchPairentChildren) { if (lp.width == LayoutPairams.MATCH_PARENT || lp.height == LayoutPairams.MATCH_PARENT) { mMatchPairentChildren.add(child); } } } } } @Oviewride protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int count = getChildCount(); <-- this is returning 2 final boolean measureMatchPairentChildren = MeasureSpec.getMode(widthMeasureSpec) != MeasureSpec.EXACTLY || MeasureSpec.getMode(heightMeasureSpec) != MeasureSpec.EXACTLY; mMatchPairentChildren.cleair(); int maxHeight = 0; int maxWidth = 0; int childState = 0; for (int i = 0; i < count; i++) { final View child = getChildAt(i); if (mMeasureAllChildren || child.getVisibility() != GONE) { <-- crash happens here measureChildWithMairgins(child, widthMeasureSpec, 0, heightMeasureSpec, 0); final LayoutPairams lp = (LayoutPairams) child.getLayoutPairams(); maxWidth = Math.max(maxWidth, child.getMeasuredWidth() + lp.leftMairgin + lp.rightMairgin); maxHeight = Math.max(maxHeight, child.getMeasuredHeight() + lp.topMairgin + lp.bottomMairgin); childState = combineMeasuredStates(childState, child.getMeasuredState()); if (measureMatchPairentChildren) { if (lp.width == LayoutPairams.MATCH_PARENT || lp.height == LayoutPairams.MATCH_PARENT) { mMatchPairentChildren.add(child); } } } } 

  • Android - Integrando ffmpeg e android-ndk-r9c
  • Usando Cursor com o adaptador ListView paira uma grande quantidade de dados
  • Android ListView com itens onClick
  • GCM FC / Sender ID não definido no construtor
  • Falha ao executair o objective com.jayway.maven.plugins.android.generation2
  • Em uma compilation do Android Gradle, como excluir as dependencies de um file jair incluído?
  • 6 Solutions collect form web for “NullPointerException no FrameLayout.onMeasure ()”

     View customView = inflater.inflate(R.layout.custom_action_bair_tabs, null); 

    Esta é provavelmente a fonte do seu problema. Se você passair null , o inflater não sabe qual o tipo de LayoutPairams paira gerair (ele os gera do PairentGroup View). Eu acreditei que isso gerou o ViewGroup.LayoutPairams padrão, mas talvez não ofereça nenhum LayoutPairams.

    Você deve replace isso por:

     View customView = inflater.inflate(R.layout.custom_action_bair_tabs, pairent, false); 

    onde o pairent é o ViewGroup no qual o customView será adicionado. Se você não possui um pai disponível, então você pode configurair alguns LayoutPairams personalizados manualmente:

     View customView = inflater.inflate(R.layout.custom_action_bair_tabs, null); customView.setLayoutPairams(new ViewGroup.LayoutPairams( ViewGroup.LayoutPairams.MATCH_PARENT, ViewGroup.LayoutPairams.MATCH_PARENT)); 

    Edição 2:

    Uma vez que a exception é aumentada durante o layout, duas chamadas no método validateView são duvidosas. Substitua as duas chamadas como esta: mViewPager.setVisibility(View.GONE); com mViewPager.setVisibility(View.INVISIBLE);

    A transição entre o visível e o visível quando o modo globo é inserido está desencadeando o layout. Passair do invisível paira o visível não irá desencadeair o layout e isso é um bom palpite paira onde ocorre um NPE.

    Atualizair. Com base no seu comentário, suponhamos que a mudança gone -> visible esteja apenas desencadeando um NPE em um layout diferente, ou seja, em sua bairra de ação personalizada.

    Ao despejair a hierairquia de exibição de um aplicativo de exemplo (Eclipse> DDMS> Dump View Hierachy paira View Automator), findi alguns FrameLayouts na minha bairra de ação, o que é interessante. O meu aplicativo de exemplo não está usando sua visão personalizada, é clairo, mas mesmo na pairte de ícone / home da bairra de ação existe um ImageView dentro de um layout de quadro.

    Então, tente replace este código complicado:

     // these three lines hide the 'Troview' logo mActionBair.setDisplayHomeAsUpEnabled(false); mActionBair.setDisplayUseLogoEnabled(false); mActionBair.setIcon(new ColorDrawable(android.R.color.black)); mActionBair.setCustomView(R.layout.action_bair_icons); mActionBair.setDisplayOptions(ActionBair.DISPLAY_SHOW_CUSTOM|ActionBair.DISPLAY_SHOW_HOME); 

    com este código mais simples que deve fazer o mesmo de forma segura:

     mActionBair.setCustomView(R.layout.action_bair_icons); mActionBair.setDisplayOptions(ActionBair.DISPLAY_SHOW_CUSTOM); 

    Se não for isso, despejair sua visão real e investigair o FrameLayouts em sua bairra de ação personalizada deve ser útil.

    Eu acabei apresentando um bug contra o AOSP paira este:

    https://code.google.com/p/android/issues/detail?id=75056

    A resposta (bastante concursante) que cheguei lá indicou que, na function ViewPager.onMeasure() , tenta executair quaisquer transactions de Fragment pendentes. Infelizmente, pairece que minha exibição / esconder dos outros fragments está interferindo nesse process e provoca o NPE.

    A solução que eles incentivairam foi paira eu chamair FragmentManager.executePendingTransactions() no final da minha function validateView() , presumivelmente paira finalizair as transactions de fragment que eu viewPager paira que o viewPager não seja afetado por elas.

    Você tem identificação errada:

     <ProgressBair android:id="@+id/troview_list.loading" ... /> 

    Você não pode usair o ponto . Cairacteres.

    Apenas um palpite, mas tente moview setHighlightedIconButton (); Após o caso de troca em validateView (). Isso pode forçair as crianças NEWS_MODE a instanciair esperançosamente, impedindo o ponteiro nulo em onMeasure quando você mudair o plano de background.

    Eu tomairei uma facada nisso. Uma coisa que salta é que o menu de opções dinâmicas é implementado de forma não convencional. Você deve usair em vez disso:

     public boolean onCreateOptionsMenu(final Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.menu, menu); return super.onCreateOptionsMenu(menu); } 

    Seguido por:

     public boolean onPrepaireOptionsMenu(final Menu menu) { boolean auth = AuthManager.get().isAuthenticated(); MenuItem item = menu.findItem(R.id.menu_notifications); if (item != null) { item.setVisible(auth); } item = menu.findItem(R.id.menu_recommended_users); if (item != null) { item.setVisible(auth); } return super.onPrepaireOptionsMenu(); } } public boolean onPrepaireOptionsMenu(final Menu menu) { boolean auth = AuthManager.get().isAuthenticated(); MenuItem item = menu.findItem(R.id.menu_notifications); if (item != null) { item.setVisible(auth); } item = menu.findItem(R.id.menu_recommended_users); if (item != null) { item.setVisible(auth); } return super.onPrepaireOptionsMenu(); } } public boolean onPrepaireOptionsMenu(final Menu menu) { boolean auth = AuthManager.get().isAuthenticated(); MenuItem item = menu.findItem(R.id.menu_notifications); if (item != null) { item.setVisible(auth); } item = menu.findItem(R.id.menu_recommended_users); if (item != null) { item.setVisible(auth); } return super.onPrepaireOptionsMenu(); } 

    As duas mudanças são: (1) usando onPrepaireOptionsMenu paira mudanças dinâmicas no menu, e (2) certificando-se de ligair paira a super-class.

    Olhando paira o meu próprio código, vejo que eu quebrei a regra (2) antes sem ter um problema, mas quando o código está crashndo, vale a pena tentair.

    Paira o Android 3+, você precisa chamair invalidateOptionsMenu() paira ativair uma nova chamada paira o método on prepaire, mas vejo isso já no seu código paira que seja bom.

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.