@gochag

Диалоговом окне, почему получаю исключение NulPointerException?

Здравствуйте. Пишу приложение менеджер паролей, в нем реализовал функцию генерацию паролей.Что бы генератор заработал в нее надо передать следующие параметры(длину пароля, АБВ,123 и символы ). Хочу реализовать эти функции в диалоговом окне с заранее установленным layout.dialog_signin.xml .
public void dialogPanel(){
        final AlertDialog.Builder mBulder = new AlertDialog.Builder(this);
        View linearlayout = getLayoutInflater().inflate(R.layout.dialog_signin, null);
        mBulder.setView(linearlayout);

        final NumberPicker numberPicker = (NumberPicker) getWindow().findViewById(R.id.numberPicker);
        numberPicker.setMinValue(6);
        numberPicker.setMaxValue(16);

        checkABC = (CheckBox) findViewById(R.id.checkABC);
        check123 = (CheckBox) findViewById(R.id.check123);
        checkSymbol = (CheckBox) findViewById(R.id.checkSymbol); 
        
        Button dialogSave = (Button) getWindow().findViewById(R.id.dialogSave);
        
        dialogSave.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
            Toast.makeText(getApplicationContext(),"работает",Toast.LENGTH_SHORT).show();
            }
        });

        mBulder.create();
        mBulder.show();
    }
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="wrap_content" android:id="@+id/dialogNumberText">
    <TextView
            android:text="Generator"
            android:layout_width="match_parent"
            android:id="@+id/textView7"
            android:textSize="24sp"
            android:gravity="center"
            android:background="#FFFFBB33"
            android:textColor="#ffffff"
            android:fontFamily="sans-serif"
            android:textStyle="normal|bold" android:layout_height="50dp"/>
    <NumberPicker
            android:layout_width="match_parent"
            android:layout_height="wrap_content" android:id="@+id/numberPicker"/>
    <CheckBox
            android:text="Заглавные буквы"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/checkABC"/>
    <CheckBox
            android:text="Цифры"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/check123"/>
    <CheckBox
            android:text="Символы"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/checkSymbol"/>
    <Button
            android:text="Button"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/dialogSave" />
</LinearLayout>

//исключение
E/AndroidRuntime: FATAL EXCEPTION: main
                  Process: com.example.comand.key, PID: 30520
                  java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.NumberPicker.setMinValue(int)' on a null object reference
                      at com.example.comand.key.AddActivity.dialogPanel(AddActivity.java:96)
                      at com.example.comand.key.AddActivity$1.onCheckedChanged(AddActivity.java:53)
                      at android.widget.CompoundButton.setChecked(CompoundButton.java:154)
                      at android.widget.CompoundButton.toggle(CompoundButton.java:113)
                      at android.widget.CompoundButton.performClick(CompoundButton.java:118)
                      at android.view.View$PerformClick.run(View.java:19911)
                      at android.os.Handler.handleCallback(Handler.java:739)
                      at android.os.Handler.dispatchMessage(Handler.java:95)
                      at android.os.Looper.loop(Looper.java:135)
                      at android.app.ActivityThread.main(ActivityThread.java:5275)
                      at java.lang.reflect.Method.invoke(Native Method)
                      at java.lang.reflect.Method.invoke(Method.java:372)
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:910)
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:705)
  • Вопрос задан
  • 185 просмотров
Решения вопроса 1
thelongrunsmoke
@thelongrunsmoke
Программист
findViewById надо вызывать на вью, в данном случае переменной linearlayout.
Ответ написан
Пригласить эксперта
Ответы на вопрос 1
zagayevskiy
@zagayevskiy Куратор тега Java
Android developer at Yandex
Ищи вьюхи в линеарлэйате. А вообще алертдиалог - дно, используй диалогфрагмент.
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы