2012-02-15 19 views
6

OK, ho appena acceso il mio TimePickerDialog in un widget TimePicker direttamente visibile nell'attività su cui sto lavorando a causa della domanda dei clienti.TimePicker NullPointerException su ICS

Il problema è quando premo una delle frecce su detto TimePicker, ottengo un NullPointerException.

Giusto per chiarire, nessun codice cosa così mai è attaccato alla TimePicker tranne questa linea nel metodo della mia attività onCreate():

((TimePicker) findViewById(R.id.time_picker)).setIs24HourView(true);

ho trovato this post sui Forum di Google per quanto riguarda questo problema, ma non molto aiuto.

Here's my error log, purtroppo non penso che sarà di grande aiuto.

Questo problema viene visualizzato solo durante i test in ICS (Android 4.0 +). Qualcuno è stato in grado di risolvere questo problema?

+0

non ero in grado di riprodurlo !!!! – dira

+0

Hai impostato un listener sul time picker? – LuxuryMode

+0

avendo lo stesso problema, ma ho eseguito una semplice app in 4.0 e funziona. hmm. – Mikey

risposta

0

appena scritto un'applicazione di esempio e nessun errore trovato in Galaxy SIII (4,0):

import android.app.Activity; 
import android.os.Bundle; 
import android.widget.TextView; 
import android.widget.TimePicker; 
import android.widget.TimePicker.OnTimeChangedListener; 

public class TimePickerTestActivity extends Activity implements OnTimeChangedListener{ 

    private TimePicker tpTime = null; 
    private TextView tvTime = null; 
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     tvTime = (TextView)this.findViewById(R.id.tv_time); 

     tpTime = (TimePicker)this.findViewById(R.id.tp_time); 
     tpTime.setIs24HourView(Boolean.TRUE); 
     tpTime.setOnTimeChangedListener(this); 

    } 
    public void onTimeChanged(TimePicker tp, final int hrOfDay, final int min) { 
     if(tp.equals(tpTime)){ 
      tvTime.post(new Runnable(){ 

       public void run() { 
        tvTime.setText(hrOfDay+":"+min); 
       } 

      }); 
     } 
    } 
} 

E l'xml di layout:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:orientation="vertical" > 

    <TimePicker android:id="@+id/tp_time" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" /> 

    <TextView android:id="@+id/tv_time" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" /> 
</LinearLayout> 

FYI: http://developer.android.com/reference/android/widget/TimePicker.html

Problemi correlati