I am trying to develop a dialogue having a textview and a numberpicker . When I am trying to set Min value of number picker it gets exception . THe code of the dialogue is as follows :
if ( v== text_mess_limit || v == text_mess_limit_text)
{
final Dialog dialog = new Dialog(this);
dialog.setContentView(R.layout.settings_number_picker_dialogue);
dialog.setTitle("Text Messages limit");
// set the custom dialog components - text, image and button
TextView text = (TextView) dialog.findViewById(R.id.text);
text.setText("Set number of messages to save");
np = (NumberPicker) findViewById(R.id.numberPicker1);
np.setMinValue(0);
np.setMaxValue(10);
np.setWrapSelectorWheel(false);
np.setOnValueChangedListener(this);
Button dialogButton = (Button) dialog.findViewById(R.id.dialogButtonCancel);
// if button is clicked, close the custom dialog
dialogButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
}
The report of logcat is as follows :
11-22 11:33:56.184: E/AndroidRuntime(23521): java.lang.NullPointerException
11-22 11:33:56.184: E/AndroidRuntime(23521): at com.commlink.messaging.Settings_Activity.onClick(Settings_Activity.java:143)
11-22 11:33:56.184: E/AndroidRuntime(23521): at android.view.View.performClick(View.java:4471)
11-22 11:33:56.184: E/AndroidRuntime(23521): at android.view.View$PerformClick.run(View.java:18784)
11-22 11:33:56.184: E/AndroidRuntime(23521): at android.os.Handler.handleCallback(Handler.java:808)
11-22 11:33:56.184: E/AndroidRuntime(23521): at android.os.Handler.dispatchMessage(Handler.java:103)
11-22 11:33:56.184: E/AndroidRuntime(23521): at android.os.Looper.loop(Looper.java:193)
11-22 11:33:56.184: E/AndroidRuntime(23521): at android.app.ActivityThread.main(ActivityThread.java:5330)
11-22 11:33:56.184: E/AndroidRuntime(23521): at java.lang.reflect.Method.invokeNative(Native Method)
11-22 11:33:56.184: E/AndroidRuntime(23521): at java.lang.reflect.Method.invoke(Method.java:515)
11-22 11:33:56.184: E/AndroidRuntime(23521): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:828)
11-22 11:33:56.184: E/AndroidRuntime(23521): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:644)
11-22 11:33:56.184: E/AndroidRuntime(23521): at dalvik.system.NativeStart.main(Native Method)
The Settings_Activity.java:143 line is as follows :
np.setMinValue(0);
Why am I getting this error ? How can I solve this ?
a dialogue having a textview and a numberpicker
Then access NumberPicker
View in same way as accessing TextView
from Dialog
.
Change
np = (NumberPicker) findViewById(R.id.numberPicker1);
to
np = (NumberPicker) dialog. findViewById(R.id.numberPicker1);