Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ViewRootImpl not in Android SDK

Tags:

java

android

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

like image 463
user3381726 Avatar asked Mar 18 '14 13:03

user3381726


1 Answers

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?

like image 180
laalto Avatar answered Oct 10 '22 16:10

laalto