TimePicker NullPointerException for ICS

Ok, so I just switched my TimePickerDialog to the TimePickerDialog widget, which is directly displayed in the action I'm working on, due to customer requirements.

The problem is that when I click any of the arrows on the specified TimePicker , I get a NullPointerException.

Just to make it clear, no code that has ever been attached to TimePicker , other than this line in the onCreate() method of my activity:

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

I found this post in Google forums regarding this issue, but didn’t help much.

Here is my error log , I, unfortunately, do not think it will be very useful.

This problem only occurs when testing in ICS (Android 4.0+). Could anyone solve this problem?

+6
source share
1 answer

I just wrote an example application and no error was detected 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); } }); } } } 

And the xml 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

0
source

Source: https://habr.com/ru/post/908549/


All Articles