views:

1939

answers:

7

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"/>
+1  A: 

If using Eclipse, run a clean build (Project/Clean...); this can often clear issues with the resources not being compiled correctly.

Charles Duffy
+1  A: 

Did you try any of the solutions listed here? http://stackoverflow.com/questions/885009/r-cannot-be-resolved-android-error

Also, look for your R.java file. Are there any errors with it?

anothem
A: 

Go in your main.xml file, delete a char and rewrite it. That will generate the R file again.

LucaB
+1  A: 

Check the contents of the 'gen' folder, is there an R.java file in there? If so what package is it in? Is it in the same package as your your activity?

satur9nine
A: 

if you posted full your main.xml file, then it's not right. You must write a namespace of xml:

xmlns:android="http://schemas.android.com/apk/res/android"

for example:

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

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/label"
    android:layout_width="78dip"
    android:layout_height="65dip"
    android:paddingTop="4dip"
    android:textSize="12dip"
    android:singleLine="true"
    android:ellipsize="end"
    android:textColor="@color/bright_text_dark_focused"
    android:gravity="center_horizontal|center_vertical" />
Demand
+2  A: 

You have to import your R class

import com.TestApp.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"/>
Pentium10
A: 

make sure you do not have any xml files with capitals in the name.

I had the same problem.

all the file names in res layout must be lower case only

Arturski