Good day.

I apologize in advance if a similar topic has appeared, this is my first application and I still have a lot to learn.

I have CalendarView and TextView. When you click on the TextView, a calendar should appear in the alertDialog.

Logcat:

`FATAL EXCEPTION: main Process: dp.develop.ru.startandroid.dp_6, PID: 8603 java.lang.IllegalStateException: Could not execute method for android:onClick at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(App CompatViewInflater.java:293) //много всякого Caused by: java.lang.reflect.InvocationTargetException //много всякого Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.CalendarView.setShowWeekNumber(boolean)' on a null object reference` //много всякого 

Content MainActivity.java

 public class MainActivity extends AppCompatActivity { TextView DenNedeli; final int DIALOG = 1; LinearLayout linview; CalendarView calendarView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); DenNedeli = (TextView) findViewById(R.id.DenNedeli); long date = System.currentTimeMillis(); SimpleDateFormat sdf = new SimpleDateFormat("EEEE"); String dateString = sdf.format(date); DenNedeli.setText(dateString); } public void onclick(View view) { showDialog(DIALOG); } @Override protected Dialog onCreateDialog(int id) { AlertDialog.Builder adb = new AlertDialog.Builder(MainActivity.this); adb.setTitle("Выбор даты"); linview = (LinearLayout) getLayoutInflater() .inflate(R.layout.calendarik, null); return adb.create(); } @Override protected void onPrepareDialog(int id, Dialog dialog) { super.onPrepareDialog(id, dialog); if (id == DIALOG) { calendarView = (CalendarView) dialog.getWindow().findViewById(R.id.calendarView); calendarView.setShowWeekNumber(false); calendarView.setFirstDayOfWeek(1); } } } 

    1 answer 1

    Set the same view for the dialog:

     linview = (LinearLayout) getLayoutInflater() .inflate(R.layout.calendarik, null); return adb .setView(linview) .create();