2

Hello I started trying to develop Android applications today, but I have a problem:

I decided to try out making a Web View using this tutorial - http://developer.android.com/resources/tutorials/views/hello-webview.html

But when I put the code in for the OnCreate() method I get an "id connot be resolved or is not a field" error. Here is my code:

main.xml:

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

HelloWebView.java:

package com.example.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");
    }
}

I have tried cleaning, CTRL+SHIFT+O, and just completely restarting the project. There error is in the statement: mWebView = (WebView) findViewById(R.id.webview); and Eclipse just says "id cannot be resolved or is not a field"

Also, I installed everything today using the guide on developer.android.com and followed all steps correctly. I have made Java programs on this computer before so I don't think there is a problem related to the JDK/JRE.

Makar
  • 61
  • 1
  • 1
  • 6
  • I can't see anything in the code that looks wrong. Copy and paste the exact error you're seeing (including line numbers etc) – Squonk May 15 '11 at 22:48
  • I did exactly the same thing and got it to work, using android 2.2 emulator along with Eclipse 3.6.2 and latest android code. – JPM May 15 '11 at 22:51
  • It is in this line: mWebView = (WebView) findViewById(R.id.webview); and the error in Eclipse is (exactly) "id cannot be resolved or is not a field error" – Makar May 15 '11 at 23:50

5 Answers5

4

I managed to fix the problem by simply restarting my computer. I guess in order for all the development tools to work properly a computer restart is necessary? I can't believe I didn't think about doing this before though. Thanks for those who tried to help.

Makar
  • 61
  • 1
  • 1
  • 6
3

There are a couple of similar questions here. Take a look at some answers:

Community
  • 1
  • 1
Aleadam
  • 39,361
  • 9
  • 84
  • 108
  • Thank you for the response, however none of those helped me resolve the problem. I also looked over other questions and none of them helped – Makar May 15 '11 at 23:50
  • Do you see any error in the xml file? Do you have any feedback in the "Problems" tab in Eclipse? – Aleadam May 15 '11 at 23:52
  • there is nothing in the Problems tab in Eclipse in the xml or java file – Makar May 15 '11 at 23:57
  • Last resort: delete everything and retype it. Maybe you're pasting a null character or a different quote? I would guess that will show up in Eclipse, but I run out of ideas now. – Aleadam May 15 '11 at 23:59
  • I have already tried that and completely restarting the project and putting the code in. – Makar May 16 '11 at 00:01
1

Found the solution that finally worked for me after researching hours. Turns out the problem is not your R.java, All you gotta do is 'Clean' the project one last time. Save your project. And open Eclipse again. The problem is GONE!

sunami
  • 11
  • 1
0

Look into the R File Generated and see whether you see a Public Static Class called Id if so then see whether it contains a public static final int webview ( that you have created )

Karthik
  • 391
  • 4
  • 14
-1

I also get that from time to time.

This usually (or always) does it for me: Project - Clean - "your project"

rochdev
  • 3,785
  • 2
  • 19
  • 18