gtiwari333
gtiwari333

Reputation: 25146

Android: findViewById returning NULL - couldn't find out whats wrong?

I have the following layout.

When i create WebView and GestureOverlayView objects in my MainActivity class, it returns null for both of the objects.

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

My Layout :

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

When i change the above layout to the following( i moved android.gesture.GestureOverlayView inside LinearLayout) , it is working fine.

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

I couldnot figure out what's wrong with my previous layout.

Please someone explain this.

Upvotes: 1

Views: 1708

Answers (2)

Gallal
Gallal

Reputation: 4262

Many of the problems revolving around resources in Android can be solved by cleaning and rebuilding the project.

Upvotes: 1

gtiwari333
gtiwari333

Reputation: 25146

Cleaning the project solved the problem.

Upvotes: 5

Related Questions