2012-02-15 64 views
6

Dobrze, więc zmieniłem tylko mój TimePickerDialog na widżet TimePicker bezpośrednio widoczny w Aktywności, nad którą pracuję, ze względu na zapotrzebowanie klientów.TimePicker Wyjątek NullPointerException na ICS

Problem polega na naciśnięciu dowolnej ze strzałek na wspomnianym TimePicker, otrzymuję wyjątek NullPointerException.

Właśnie w celu wyjaśnienia, brak kodu, co tak zawsze jest dołączony do TimePicker oprócz tej linii w sposobie mojej działalności onCreate():

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

znalazłem this post na forach Google dotyczących tego problemu, ale niewiele pomoc.

Here's my error log, Niestety nie sądzę, że będzie to pomocne.

Ten problem pojawia się tylko podczas testowania w systemie ICS (Android 4.0 +). Czy ktoś mógł obejść ten problem?

+0

I nie był w stanie odtworzyć to !!!! – dira

+0

Czy ustawiłeś detektor w selektorze czasu? – LuxuryMode

+0

mając ten sam problem, ale uruchomiłem prostą aplikację w wersji 4.0 i działa. hmm. – Mikey

Odpowiedz

0

Wystarczy napisał przykładową aplikację i żadnego błędu znajdujący się w 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); 
       } 

      }); 
     } 
    } 
} 

a xml układ:

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

Powiązane problemy