2012-02-15 12 views
6

申し訳ありません。TimePickerDialogTimePickerウィジェットに変更しました。私が取り組んでいるアクティビティで直接表示されるのは、顧客の要望のためです。TimePicker ICSのNullPointerException

問題は、私はTimePicker言っ上の矢印のいずれかを押すと、私はNullPointerExceptionが得られます。です

だけ明確にするため、今まで私の活動のonCreate()方法で、この行を除いTimePickerに添付されているものがないコード:私はこの問題について、Googleのフォーラムにthis postを見つけ

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

が、あまり役に立たない。

Here's my error log、私は悲しげにそれはしかし多くの助けになるだろうとは思いません。

この問題は、ICS(Android 4.0以降)でテストしている場合にのみ表示されます。誰もこの問題を回避することができましたか?

+0

私がすることができませんでしたそれを再現!!!! – dira

+0

時間ピッカーでリスナーを設定しましたか? – LuxuryMode

+0

は同じ問題を抱えていますが、4.0で単純なアプリを実行しています。うーん。 – Mikey

答えて

0

ただギャラクシー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); 
       } 

      }); 
     } 
    } 
} 

とレイアウトのxml:

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

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