6

Just playing around a bit (I do know View.getRootView()), I manually stepped my way up to the root and even beyond.

...
View tv=(View)mv.getParent();
View uv=(View)tv.getParent();
...

Actually I thought that at one point I would run into a NullPointerException, but instead I got

03-18 13:07:45.554 13568 13568 E AndroidRuntime: java.lang.ClassCastException: android.view.ViewRootImpl cannot be cast to android.view.View

Okay, fine, that looks reasonable, too.

I didn't know about ViewRootImpl yet, so I decided to pick up the topic and investigate it a bit.

However, when I do

ViewRootImpl wv=(View)vv.getParent();

I get a (deserved)

[javac] /home/jagged/Downloads/android/motog/firsttry/src/tk/wellthen/main.java:285: cannot find symbol
[javac] symbol  : class ViewRootImpl
[javac] location: class tk.wellthen.main
[javac]     ViewRootImpl wv=(View)vv.getParent();
[javac]     ^

from the compiler, but still, when I fully qualify it according to the logcat output above, I get the (almost) same error message. (And I even copy-pasted it from the logcat output to avoid typos.)

Needless to say that upon trying to import android.view.ViewRootImpl. the same message appeared, just for another source line.

Also, Google doesn't seem to find it useful to mention it even with a single word throughout the API docs. I take it that it is mainly used for internals, but that's no reason if you ask me.

There are 138 hits for "ViewRootImpl" on stackoverflow.com (well, now it should be at least 139), but they are completely irrelevant in this context (if I didn't miss something special).

I've taken a look at some other sites, and found, for example, this source code, but I somehow doubt it'd be useful to fake it into the SDK in order to explore it?

Any advices? Thanks in advance

user3381726
  • 153
  • 1
  • 7
  • Related - the error you see has been logged as a bug against the platform here: [Issue 197291: AppCompatDialog crashes on selecting text](https://code.google.com/p/android/issues/detail?id=197291) – Richard Le Mesurier Oct 27 '16 at 08:48

2 Answers2

10

ViewRootImpl is annotated with @hide. This excludes the class from the stub android.jar used for development. The class is there on an actual runtime environment.

See also: What does @hide mean in the Android source code?

Community
  • 1
  • 1
laalto
  • 150,114
  • 66
  • 286
  • 303
-1

If you use Eclipse, ViewRootImpl is invisible.
You can use the Android Studio instead.

Mike Yang
  • 2,581
  • 3
  • 24
  • 27