Почему вызов findViewById(android.R.id.content).getRootView()
в onPause или onStop возвращает NPE, но не когда я вызываю его в onCreate?findViewById (android.R.id.content) .getRootView() nullPointerException
3
A
ответ
1
Вот код android.view.View.getRootView()
:
public View getRootView() {
if (mAttachInfo != null) {
final View v = mAttachInfo.mRootView;
if (v != null) {
return v;
}
}
View parent = this;
while (parent.mParent != null && parent.mParent instanceof View) {
parent = (View) parent.mParent;
}
return parent;
}
это по крайней мере возвращать сам вид.
После того как я попробовал войти findViewById(android.R.id.content)
и findViewById(android.R.id.content).getRootView()
в OnStop, OnPause, OnCreate, onResume, он работал все в порядке. Нет NPE.
Вы можете задать свой код операции?
0
Я не смог воспроизвести эту ошибку на Android 4.2.2. Возможно, вы получите это NullPointerException от чего-то другого. Кстати, findViewById(android.R.id.content)
возвращает rootview так getRootView()
обычно недействителен.
Смежные вопросы
- 1. Разница между findViewById (R.id.content) и getRootView()
- 2. NullPointerException findViewById()
- 3. findViewById nullPointerException
- 4. TextView findviewbyID NullpointerException
- 5. android нетривиальный findViewById NullPointerException
- 6. NullPointerException вызванные findViewById
- 7. findViewById в DialogFragment - NullPointerException
- 8. Android findViewById выбрасывает NullPointerException
- 9. Может ли findViewById (android.R.id.content) когда-либо возвращать null для Snackbars?
- 10. NullPointerException on findViewById из фрагмента
- 11. View getRootView возвращает себя
- 12. Вызовите findViewById() для определенного макета? NullPointerException на findViewById()
- 13. Jelly Bean android.R.id.content изменен?
- 14. NullPointerException во фрагментах onAttach для findViewById
- 15. Occasional NullPointerException в findViewById при вызове onRestart
- 16. Вызов FindViewById из потока обработчика - NullPointerException
- 17. NullPointerException on findViewById при замене фрагмента
- 18. Вызов findViewById() из подкласса DialogFragment дает NullPointerException
- 19. findViewById на ImageView почему setBackgroundColor дать NullPointerException
- 20. «FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS» влияет на getRootView(). GetHeight()
- 21. Является ViewGroup с id android.R.id.content всегда FrameLayout?
- 22. Android: Добавление фрагментов с android.R.id.content
- 23. Android: listview: пользовательские элементы: nullpointerexception, findviewbyid возвращает null
- 24. Ошибка NullPointerException в findviewbyid в textview в asynctask
- 25. NullPointerException при вызове findViewById(), чтобы получить вид фрагмента
- 26. NullPointerException - Spinner всегда получает значение null даже после применения findViewById()
- 27. findViewById() возвращает null
- 28. получение рисунка на холсте с использованием getRootView
- 29. setContentView и findViewById
- 30. Добавление вида сверху android.R.id.content с выравниванием
Мое лучшее угадывание onPause и onStop вы не привязаны к окну, которое держит вас. –
Попробуйте следующие две ссылки: http://stackoverflow.com/questions/4486034/get-root-view-from-current-activity http://stackoverflow.com/questions/7776768/android-what-is-android-r -id-контента используется для- –