无法在按钮中找到符号id



你好,我正在制作一个简单的android按钮,这是我的mainactivity文件

package dk.troll.android;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.widget.Button;
import android.view.View;
import android.view.View.OnClickListener;
public class MainActivity extends Activity {
    Button button;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        addListenerOnButton();
    }
    public void addListenerOnButton() {
        button = (Button) findViewById(R.id.button1);
        button.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {
              Intent browserIntent = 
                            new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.troll.dk"));
                startActivity(browserIntent);
            }
        });
    }
}

这是我的XML文件

<?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"
    >
<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Lorem Ipsum and so much other stuff"
    />
<Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button - Go To Troll" />
</LinearLayout>

在这行button = (Button) findViewById(R.id.button1);中,我得到了错误

无法找到symbol:变量id location:class R

由于类

的内容
r

是自动生成的,我如何修复这个错误?

首次重启eclipse

然后这样做:

1。

2。确保所有递归文件没有任何错误,然后尝试从project then clean中清理项目。

3。构建项目

最新更新