开发者

id can not be resolved or is not field

package com.commonsware.android.layouts;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import java.util.Date;
public class NowRedux1 extends Activity implements View.OnClickListener  {
    Button btn;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.main);
        **btn=(Button)findViewById(R.id.button);///Error**
        btn.setOnClickListener(this);
        updateTime();
    }
    public void onClick(View view){
        updateTime();

    }
    private void updateTime(){
        btn.setText(new Date().toString());
    }


}

And this is my main.xml file

<?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="@string/hello"
    />
</LinearLayout>

And this is my R.java File

package com.commonsware.android.layouts;

public final class R {
    public static final class attr {
    }
    public static final class drawable {
        public static final int icon=0x7f020000;
开发者_Python百科    }
    public static final class layout {
        public static final int main=0x7f030000;
    }
    public static final class string {
        public static final int app_name=0x7f040001;
        public static final int hello=0x7f040000;
    }
}

please send the salution


As I can tell from your formatting your main.xml doesn't contain any buttons. You'll have to add a button with the id button.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜