2011-02-18 36 views
0

我得到以下行錯誤:時間選擇器插件 - 「號不能得到解決或不是場」

mTimeDisplay = (TextView) findViewById(R.id.timeDisplay); 
mPickTime = (Button) findViewById(R.id.pickTime); 

雖然在這個階段,我只是從複製粘貼的東西教程,只是爲了得到它的感覺..所以,我哪裏錯了傢伙?

這是java文件作爲一個整體:

package com.example.hellotimepicker; 

import java.util.Calendar; 

import android.app.Activity; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.Button; 
import android.widget.TextView; 

public class HelloTimePicker extends Activity { 
    /** Called when the activity is first created. */ 

    private TextView mTimeDisplay; 
    private Button mPickTime; 

    private int mHour; 
    private int mMinute; 

    static final int TIME_DIALOG_ID = 0; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     // capture our View elements 
     mTimeDisplay = (TextView) findViewById(R.id.timeDisplay); 
     mPickTime = (Button) findViewById(R.id.pickTime); 

     // add a click listener to the button 
     mPickTime.setOnClickListener(new View.OnClickListener() { 
      public void onClick(View v) { 
       showDialog(TIME_DIALOG_ID); 
      } 
     }); 

     // get the current time 
     final Calendar c = Calendar.getInstance(); 
     mHour = c.get(Calendar.HOUR_OF_DAY); 
     mMinute = c.get(Calendar.MINUTE); 

     // display the current date 
     updateDisplay(); 

    } 

// updates the time we display in the TextView 
    private void updateDisplay() { 
     mTimeDisplay.setText(
      new StringBuilder() 
        .append(pad(mHour)).append(":") 
        .append(pad(mMinute))); 
    } 

    private static String pad(int c) { 
     if (c >= 10) 
      return String.valueOf(c); 
     else 
      return "0" + String.valueOf(c); 
    } 
} 

回答

0

聽起來像你錯過了從教程

+0

或忘了添加時間顯示字段。檢查res/layout/main.xml中的timeDisplay視圖。 – Karan 2011-02-18 14:25:58

+0

這樣做:-)讚賞,thx! *編輯*佈局thingy :-P – redra75 2011-02-18 14:40:55

0

只是想分享我與原來的教程經驗複製佈局(XML代碼)版本,因爲這可能是有用的。早些時候,我用:

import android.R; 

main不能在該行來解決:

setContentView(R.layout.main); 

所以我改變了"import android.R;"到:

import com.example.hellodatepicker.R; //to match with the package name 

,並發現它運行良好。

相關問題