问题
As per Javadocs:
public Date (int year, int month, int day)
This constructor was deprecated in API level 1.
Date date = new Date(year,month,date);
This constructor was deprecated in API Level 1 but my Eclipse isn't giving me deprecation warning in the Android project I'm creating. What can be the issue? Is there a silly mistake that I'm making?
- I've compiled the project at
4.0
version. - I've checked the Lint preferences and it's fine.
- I've not set an
@SuppressWarnings
, so that is ruled out.
This is the code that I'm using:
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.DatePickerDialog.OnDateSetListener;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Paint;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;
@Override
protected Dialog onCreateDialog(int id) {
Calendar mCalen = Calendar.getInstance();
int day = mCalen.get(Calendar.DAY_OF_MONTH);
int month = mCalen.get(Calendar.MONTH);
int year = mCalen.get(Calendar.YEAR);
return new DatePickerDialog(this, new OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
String newDate = new StringBuilder().append(dayOfMonth)
.append("/").append(monthOfYear + 1).append("/")
.append(year).toString();
date = null;
timeStamp = null;
dateStamp = 0;
date = newDate;
timeStamp = new Date(year, monthOfYear, dayOfMonth);
dateStamp = timeStamp.getTime();
dateTextView.setText(date);
}
}, year, month, day);
}

回答1:
Have a look at:
Preferences | Java | Compiler | Errors/Warnings | Deprecated and Restricted API
Make sure Deprecated API is set to Warning. Ensure the code which is deprecated has a @Deprecated annotation either at the class / method or in the JavaDoc.
回答2:
Check for following:
Properties > Java > Compiler > Errors/Warnings > Deprecated and restricted API
Select Warning
for Deprecated API.

回答3:
You have to turned on warnings of your related project from project properties. To do this follow these steps:
- Right click on your project and go in project properties.
- Select Java Compiler tab and expand it.
- Now you see error/warning tab. Now enable that check box and change project setting.
or remove check box from project specific error/warnings settings and click on Android Lint Preferences tab and search for deprecated Serverity.
来源:https://stackoverflow.com/questions/22855836/eclipse-not-showing-deprecated-warning