2011-02-26 73 views
0
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()); 
    } 


} 

這是我的main.xml文件ID不能得到解決或不能現場

<?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> 

這是我的R.java文件

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

請發送salution

回答

2

正如我從格式中可以看出你的main.xml不包含任何按鈕。你必須添加一個帶有ID按鈕的按鈕。

相關問題