Android:findViewById返回NULL - 无法找出什么错误?

gti*_*333 1 layout android

我有以下布局.

当我在MainActivity类中创建WebViewGestureOverlayView对象时,它会返回null两个对象.

GestureOverlayView gesturesView = (GestureOverlayView) findViewById(R.id.gestures);
WebView webView = (WebView) findViewById(R.id.webview);
Run Code Online (Sandbox Code Playgroud)

我的布局:

<?xml version="1.0" encoding="utf-8"?>
<android.gesture.GestureOverlayView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/gestures"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <WebView
            android:id="@+id/webview"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" />
    </LinearLayout>
</android.gesture.GestureOverlayView>
Run Code Online (Sandbox Code Playgroud)

当我将上面的布局更改为以下(我移动android.gesture.GestureOverlayView到里面LinearLayout),它工作正常.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <android.gesture.GestureOverlayView
        android:id="@+id/gestures"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <WebView
            android:id="@+id/webview"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" />
    </android.gesture.GestureOverlayView>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

我无法弄清楚我以前的布局有什么问题.

请有人解释一下.

gti*_*333 5

清理项目解决了这个问题.