J2ME日历添加日期问题

ArK*_*ArK 1 calendar java-me

我在java vm 1.6下使用eclipse脉冲星.问题是java.util Calendar类add方法引发了一个错误"方法add(int,int)是未定义的类型Calendar"但它的文档很好.

package caltest;

import java.util.Calendar;
import java.util.Date;

import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;

public class caltest extends MIDlet {

    public caltest() {
        // TODO Auto-generated constructor stub
    }

    protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
        // TODO Auto-generated method stub

    }

    protected void pauseApp() {
        // TODO Auto-generated method stub


    }

    protected void startApp() throws MIDletStateChangeException {
        // TODO Auto-generated method stub
            Calendar cal=Calendar.getInstance();
        cal.setTime(new Date());
        cal.add(Calendar.DAY_OF_MONTH, -5);
    }

}
Run Code Online (Sandbox Code Playgroud)

Sus*_*Pal 6

这个怎么样?

// Subtract 5 days from the time in the calendar object
cal.setTime(new Date(cal.getTime().getTime() - 5 * 86400000));
Run Code Online (Sandbox Code Playgroud)

要么

// Subtract 5 days from "now" and set it in the calendar object
cal.setTime(new Date((new Date()).getTime() - 5 * 86400000));
Run Code Online (Sandbox Code Playgroud)