启动 DatePicker 对象或 DatePickerDialog 时出现错误:在 mi Eclipse LogCat 调试控制台中显示此消息:
06-15 01:02:33.935: E/DatePicker(7667): set months
我已经尝试了一些东西,并且我已经阅读了两天的帖子,对我来说是不可能跳过这个错误的。对于代码,没有任何结果。对于 xml 文件,没有任何结果......我对这个错误感到疯狂。我正在复制 android 开发人员参考代码,错误再次显示。
public class GestionAlertas extends Activity
{
private TextView mDateDisplay;
private Button mPickDate;
private int mYear;
private int mMonth;
private int mDay;
static final int DATE_DIALOG_ID = 0;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.gestion_alertas);
final Calendar c = Calendar.getInstance();
mYear = c.get(Calendar.YEAR); mMonth = c.get(Calendar.MONTH); mDay = c.get(Calendar.DAY_OF_MONTH);
mDateDisplay = (TextView) findViewById(R.id.dateDisplay);
mPickDate = (Button) findViewById(R.id.pickDate);
mPickDate.setOnClickListener(new View.OnClickListener() { public void onClick(View v)
{
showDialog(DATE_DIALOG_ID);
}});
updateDisplay();
}
@Override
protected Dialog onCreateDialog(int id)
{
switch (id)
{
case DATE_DIALOG_ID:
return new DatePickerDialog(this, mDateSetListener, mYear, mMonth, mDay );
}
return null;
}
private DatePickerDialog.OnDateSetListener mDateSetListener = new DatePickerDialog.OnDateSetListener() { public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth)
{
mYear = year; mMonth = monthOfYear; mDay = dayOfMonth;
updateDisplay();
}};
private void updateDisplay()
{
mDateDisplay.setText( new StringBuilder().append(mMonth + 1).append("-").append(mDay).append("-").append(mYear).append(" ") );
}
请帮我。
编辑
日志猫:
06-15 11:14:38.920: D/dalvikvm(25412): GC_EXTERNAL_ALLOC 释放 89K,
47% 空闲 2895K/5447K, 外部 1249K/1288K, 暂停 16ms 06-15
11:14:38.995: D/InputTransport(25412):输入通道构造:
name='40a1d3a8 com.hide.hide/com.hide.hide.GestionAlertas (client)',
ashmemFd=47, receivePipeFd=48, sendPipeFd=49 06-15 11:14:39.075:
I/ViewRoot( 25412): !@FINISH DRAWING :
com.hide.hide/com.hide.hide.GestionAlertas 06-15 11:14:39.080:
I/ViewRoot(25412): !@finishDrawing 完成 :
com.hide.hide/com .hide.hide.GestionAlertas06-15 11:14:40.800: D/(25412): 1 <--- 日志
06-15 11:14:40.920: E/DatePicker(25412): 设置月份 <---------错误
06-15 11:14:40.930: D/(25412): 2 <--- 日志
06-15 11:14:40.965: D/InputTransport(25412): 输入通道
构造: name='40a3e268 viernes, 15/jun/2012 (client)',
ashmemFd=50, receivePipeFd=51, sendPipeFd=52 06-15 11:14:40.985:
D/dalvikvm(25412): GC_CONCURRENT 释放 97K, 46% 释放 3082K/5639K,
外部 3162K/3530K, 暂停 2ms+3ms 06-15 11:14:41.070:
I/ViewRoot(25412): ! @FINISH DRAWING : viernes, 15/jun/2012 06-15
11:14:41.075: I/ViewRoot(25412): !@finishDrawing 完成 :
viernes, 15/jun/2012
编码:
private DatePickerDialog.OnDateSetListener escuchadorFecha = new DatePickerDialog.OnDateSetListener() { public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth)
{
mYear = year; mMonth = monthOfYear; mDay = dayOfMonth;
edFecha.setText( String.valueOf(mYear) + "/" + String.valueOf(mMonth) + "/" + String.valueOf(mDay) );
}};
@Override
protected Dialog onCreateDialog(int id)
{
switch( id )
{
case DLG_FECHA:
Log.d("", "1");
DatePickerDialog r = new DatePickerDialog(this, escuchadorFecha, mYear, mMonth, mDay );
Log.d("", "2");
return r;
}
return null;
}
显然,这段代码没有 xml 对象。