eclipse error with android: id cannot be resolved or is not a field

Posted by Jaynathan Leung on Stack Overflow See other posts from Stack Overflow or by Jaynathan Leung
Published on 2010-12-24T17:44:55Z Indexed on 2010/12/24 17:54 UTC
Read the original article Hit count: 184

Filed under:
|
|
|

Hi, I just started playing around with android development, and already with just an attempt at making a button, I have encountered a problem. The error I'm given in the following code is right on "R.id.button1". It says id cannot be resolved or is not a field. Do I need to manually reference every single object I make in the layout xml file? I found that this did work, but it does seem to be a bit much for every button I want to make...

package com.example.helloandroid;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;


public class HelloAndroid extends Activity {
    /** Called when the activity is first created. */

 private Button button1;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        button1 = (Button)findViewById(R.id.button1);
        button1.setOnClickListener(new OnClickListener()
        {
         public void onClick(View v)
         {
          finish();          
         }        
        });
    }
}

© Stack Overflow or respective owner

Related posts about android

Related posts about eclipse