Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R.id cannot be resolved [duplicate]

So I copied this tutorial example thing right from Google's android site and I ma getting an error that R.id cannot be resolved.

Here is my Java file

package com.TestApp.HelloWebView;

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;

public class HelloWebView extends Activity {
    WebView mWebView;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        mWebView = (WebView) findViewById(R.id.webview);
        mWebView.getSettings().setJavaScriptEnabled(true);
        mWebView.loadUrl("http://www.google.com");
    }

}

Here is my res/layout/main.xml

<?xml version="1.0" encoding="utf-8"?>

<WebView android:id="@+id/webview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"/>
like image 454
Soren Avatar asked Mar 20 '10 16:03

Soren


1 Answers

You have to import your R class

import com.TestApp.HelloWebView.R;

Also as Demand posted you have to use a namespace for your layout.

?xml version="1.0" encoding="utf-8"?>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/webview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"/>
like image 109
Pentium10 Avatar answered Oct 10 '22 11:10

Pentium10