# Fehler: Veraltete API



## Lucaaa (14. Nov 2018)

Hallo!
Ich bekomme beim build folgenden Fehler:
`uses or overrides a deprecated API.`

Hier die Klasse

```
package com.ludevstudio.schoolmanager.dialogs;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.support.design.widget.Snackbar;
import android.support.v7.widget.CardView;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.Toast;

import com.ludevstudio.schoolmanager.R;
import com.ludevstudio.schoolmanager.TasksFragment;
import com.ludevstudio.schoolmanager.data.TasksSrc;

import java.text.SimpleDateFormat;
import java.util.Date;

public class AddTask {
    Button btnClose, btnDone;
    Switch switchRemind;
    TextView tvRemind;
    EditText edtName;
    CardView cardRemind, cardDate;

    Context context;
TasksFragment.ListAdapter adapter;

    // Task settings

    private String name;
    private boolean doRemind;
    Date date;

    private TasksSrc src;


    public AddTask(Context context, TasksSrc src, TasksFragment.ListAdapter adapter) {
        this.context = context;

        this.src = src;
        this.adapter = adapter;


    }

    public Snackbar get() {
        View sView = ((Activity)context).getWindow().getDecorView().findViewById(android.R.id.content);
        final Snackbar sBar =Snackbar.make(sView, "Hello World", Snackbar.LENGTH_INDEFINITE);

        Snackbar.SnackbarLayout snackView = (Snackbar.SnackbarLayout) sBar.getView();
        TextView tw = (TextView) snackView.findViewById(android.support.design.R.id.snackbar_text);
        tw.setVisibility(View.INVISIBLE);
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View dialogView = inflater.inflate(R.layout.dialog_add_task, null);
        snackView.addView(dialogView);
        snackView.setPadding(0,0,0,0);



        // Components in Dialog
        btnClose = (Button) dialogView.findViewById(R.id.addtaskdialog_btn_close);
        btnDone = (Button) dialogView.findViewById(R.id.addtaskdialog_btn_done);
        edtName = (EditText) dialogView.findViewById(R.id.addtaskdialog_edt_name);



        // Toolbar Buttons
        btnClose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                SelectDateDialog selectDateDialog =new SelectDateDialog(context);
                date = selectDateDialog.showAndgetDate();
                SimpleDateFormat df =new SimpleDateFormat("dd.MM.yyyy");
                Toast.makeText(context, df.format(date), Toast.LENGTH_LONG).show();
                sBar.dismiss();
            }
        });



        return sBar;
    }



    private class SelectDateDialog {
       Context context;

       AlertDialog.Builder builder;
       DatePicker picker;
AlertDialog dialog;


       Date date;


        public SelectDateDialog(Context context) {
            AlertDialog.Builder dialogBuilder =new AlertDialog.Builder(context);
            builder.setView(picker);
            builder.setPositiveButton(context.getResources().getString(R.string.button_apply), new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    date = new Date(picker.getYear(), picker.getMonth(), picker.getDayOfMonth());
                }
            });
            builder.setNegativeButton(context.getResources().getString(R.string.button_cancel), new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    dialog.dismiss();
                }
            });

            dialog = builder.create();


             }

        public Date showAndgetDate() {
            dialog.show();
            return date;
        }
    }




}
```


----------



## mrBrown (14. Nov 2018)

Kompilier das ganze mal mit `-Xlint:all`, dann wird dir die entsprechende Stelle ausgegeben.

Die IDE sollte das aber auch darstellen können, üblicherweise als durchgestrichene Methode.


----------

