gpt4 book ai didi

Android:findViewById 返回 NULL - 无法找出问题所在?

转载 作者:行者123 更新时间:2023-11-29 14:55:38 25 4
gpt4 key购买 nike

我有以下布局。

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

GestureOverlayView gesturesView = (GestureOverlayView) findViewById(R.id.gestures);
WebView webView = (WebView) findViewById(R.id.webview);

我的布局:

<?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>

当我将上面的布局更改为以下布局时(我将 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>

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

请有人解释一下。

最佳答案

清理项目解决了问题。

关于Android:findViewById 返回 NULL - 无法找出问题所在?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7608708/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com