где я ошибся : package com.example.myapp2.UI.view.activities; import static…
- User
где я ошибся : package com.example.myapp_2.UI.view.activities;
import static java.security.AccessController.getContext;
import androidx.appcompat.app.AppCompatActivity; import androidx.fragment.app.DialogFragment;
import android.app.DatePickerDialog; import android.app.Dialog; import android.content.Context; import android.content.Intent; import android.graphics.Color; import android.graphics.drawable.ColorDrawable; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.DatePicker; import android.widget.TextView; import android.widget.Toast;
import com.example.myapp_2.Data.Discount_Get_table.DatePickerFragment; import com.example.myapp_2.R; import com.example.myapp_2.databinding.ActivityReserveTableBinding;
import java.text.DateFormat; import java.util.Calendar;
public class ReserveTableActivity extends AppCompatActivity implements DatePickerDialog.OnDateSetListener, AdapterView.OnItemSelectedListener {
code - Assistant
There seems to be one mistake in the code:
- The method onBackPressed() has been overridden inside the showCustomDialog() method, which is not allowed. onBackPressed() method should be overridden inside the activity and not inside any methods.
- User
Toast.makeText(getContext(), "Registration approved", Toast.LENGTH_SHORT).show(); ^ method Toast.makeText(Context,CharSequence,int) is not applicable (argument mismatch; AccessControlContext cannot be converted to Context) method Toast.makeText(Context,int,int) is not applicable (argument mismatch; AccessControlContext cannot be converted to Context)
- Assistant
The error message is saying that
AccessControlContextcannot be converted toContext.From the given code, it seems like the issue is with the
getContext()method inside theshowCustomDialog(View v)method.getContext()method is not a method that can be called directly from theActivity, it should be called from a View object. So, to get theContextinside theshowCustomDialog()method, you can usev.getContext()instead ofgetContext().Replace this line of code:
codeToast.makeText(getContext(), "Registration approved", Toast.LENGTH_SHORT).show();with:
codeToast.makeText(v.getContext(), "Registration approved", Toast.LENGTH_SHORT).show();