日食错误与Android:ID不能得到解决或不是场 [英] eclipse error with android: id cannot be resolved or is not a field

查看:136
本文介绍了日食错误与Android:ID不能得到解决或不是场的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始用android开发玩弄,并已经与刚刚在做一个按钮尝试,我也遇到了问题。 我在下面的code给出的错误是正确的R.id.button1。 它说的ID不能得到解决,或者不是一个领域。 我是否需要手动引用我做出在布局XML文件中的每一个对象吗?我发现,这个没有工作,但它似乎是有点多,每按钮,我想打...

 包com.example.helloandroid;

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


公共类HelloAndroid延伸活动{
    / **第一次创建活动时调用。 * /

 私人按钮按钮1;
    @覆盖
    公共无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.main);

        按钮1 =(按钮)findViewById(R.id.button1);
        button1.setOnClickListener(新OnClickListener()
        {
         公共无效的onClick(视图v)
         {
          完();
         }
        });
    }
}
 

解决方案

我已经浪费了很多时间,因为同样的问题(2周),直到我发现这个问题是不是我的,但Eclipse的。 我想有很多人有同样的问题。

只是试试这个:保存项目,关闭Eclipse,然后再次打开它。就这么简单。

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();          
         }        
        });
    }
}

解决方案

I've been wasting a lot of time (two weeks) because of the same problem until I discovered the problem wasn't mine but Eclipse's. I guess there's a lot of people with the same problem.

Just try this: Save your project, close Eclipse and then open it again. So simple.

这篇关于日食错误与Android:ID不能得到解决或不是场的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆