Получение Android Spinner NullPointerException при повороте экрана
Привет! ребята, у меня проблемы с вращением, генерирующим nullPointerExpression при повороте экрана
<com.weiwangcn.betterspinner.library.material.MaterialBetterSpinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/department_spinner"
android:hint="@string/select_department"
android:gravity="center"
android:drawableEnd="@drawable/spinner_icon"
android:textColorHighlight="@color/colorButton"
android:textColor="@color/colorButton"
android:theme="@style/AppTheme"
app:met_floatingLabel="highlight"
android:layout_marginStart="25dp"
android:layout_marginEnd="25dp"
android:layout_marginTop="5dp"/>
Внутри моего onCreateView
//MaterialBetterSpinner code goes from here
this.materialDesignSpinner = (MaterialBetterSpinner) findViewById(R.id.department_spinner);
materialDesignSpinner.setHintTextColor(Color.parseColor("#00BE84"));
materialDesignSpinner.setTextColor(Color.parseColor("#00BE84"));
materialDesignSpinner.setTextSize(17);
materialDesignSpinner.setHighlightColor(Color.parseColor("#00BE84"));
materialDesignSpinner.setUnderlineColor(Color.parseColor("#00BE84"));
callDepartment= service.getAllOpdIpdDepartments();
ArrayAdapter<String> departmentAdapter = new ArrayAdapter<>(OpdIpdAnalysis.this, android.R.layout.simple_dropdown_item_1line, new ArrayList<String>());
materialDesignSpinner.setAdapter(departmentAdapter);
callDepartment.enqueue(new Callback<List<OpdIpdDepartmentModel>>() {
@Override
public void onResponse(Call<List<OpdIpdDepartmentModel>> call, Response<List<OpdIpdDepartmentModel>> response) {
departmentLists = response.body();
if (departmentLists != null){
for (int i = 0; i<departmentLists.size(); i++){
spinnerLists.add(departmentLists.get(i).getName());
}
}
ArrayAdapter<String> adapter = (ArrayAdapter<String>) materialDesignSpinner.getAdapter();
adapter.clear();
adapter.addAll(spinnerLists);
adapter.notifyDataSetChanged();
}
Вот logcat:
E / AndroidRuntime: ИСКЛЮЧИТЕЛЬНОЕ ИСКЛЮЧЕНИЕ: основной процесс: com.example.ritecare, PID: 15345 java.lang.NullPointerException: попытка вызвать виртуальный метод void android.widget.Filter.filter (java.lang.CharSequence, android.widget.Filter $ FilterListener) 'для ссылки на нулевой объект в android.widget.AutoCompleteTextView.performFiltering (AutoCompleteTextView.java:1026) в com.weiwangcma.liber.Miber.bet.onFocusChanged (MaterialBetterSpinner.java:49) в android.view.View.handleFocusGainInternal (View.java:7478) в android.view.View.requestFocusNoSearch (View.java:12441) в android.view.View.requestFocus (Просмотреть. Java: 12415) на android.view.View.requestFocus (View.java:12382) на android.view.View.requestFocus (View.java:12324) на com.android.internal.policy. PhoneWindow.restoreHierarchyState (PhoneWindow.java:2166) в android.app.Activity.onRestoreInstanceState (Activity.java:1563) в android.app.Activity.performRestoreInstanceState (Activity.java:1518) в android.app.Instrumentation.callActivityOntationState.java: 1346) в android.app.ActivityThread.handleStartActivity (ActivityThread.java:3310) в android.app.servertransaction.TransactionExecutor.performLifecycleSequence (TransactionExecutor.java:221) в android.app.servertransaction.TransactionExecutor (TransactionExecutor.cycleToPJava: 201) в android.app.servertransaction.TransactionExecutor.executeLifecycleState (TransactionExecutor.java:173) в android.app.servertransaction.TransactionExecutor.execute (TransactionExecutor.java:97) в android.app.ActivityThread $ H.handleMessage (.java: 2016) на android.os.Handler.dispatchMessage (Handler.java:107) на android.os.Looper.loop (Looper.java:214) на android.app.ActivityThread.main (ActivityThread.java:7356)на джаva.lang.reflect.Method.invoke (собственный метод) на com.android.internal.os.RuntimeInit $ MethodAndArgsCaller.run (RuntimeInit.java:492) на com.android.internal.os.ZygoteInit.main (ZygoteInit.java): 930)