小编Jay*_*ung的帖子

eclipse错误与android:id无法解析或不是字段

我刚刚开始玩android开发,并且只是尝试制作一个按钮,我遇到了一个问题.我在下面的代码中给出的错误就在"R.id.button1"上.它表示id无法解析或不是字段.我是否需要手动引用我在布局xml文件中创建的每个对象?我发现这确实有效,但对于我想要制作的每个按钮,它似乎有点多了......

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();          
         }        
        });
    }
}
Run Code Online (Sandbox Code Playgroud)

eclipse android

4
推荐指数
1
解决办法
3万
查看次数

标签 统计

android ×1

eclipse ×1