天气应用程序:J2me构造函数

时间:2012-07-01 23:31:36

标签: java java-me midp lcdui

我在使用天气应用程序时遇到问题。构造函数应该创建一个列表,但是当应用程序运行时,它只显示一个空白屏幕。

ERROR:
';' expected

no suitable constructor found for List(javax.microedition.lcdui.List)
    constructor javax.microedition.lcdui.List.List(java.lang.String,int,java.lang.String[],javax.microedition.lcdui.Image[]) is not applicable
      (actual and formal argument lists differ in length)
    constructor javax.microedition.lcdui.List.List(java.lang.String,int) is not applicable
      (actual and formal argument lists differ in length)

//带有构造函数的类

public class WeatherMIDlet extends BaseMIDlet implements CommandListener {

private List list3;

private List getWeatherLocationView(List list3) {

        if (weatherConditionSearch == null) {
            weatherConditionSearch = new WeatherConditionSearch(this, list3);
        }
        return weatherConditionSearch; //list should dislay here!
    }

//我要创建本地城市列表的课程

public class WeatherConditionSearch extends List implements CommandListener {

    private Command okCmd, backCmd;
    private TextField locationTfld;
    private BaseMIDlet midlet;
        private List list;

    public WeatherConditionSearch(BaseMIDlet midlet, List list3) //super class is List
{
        super(list3);//error is at this line
        this.midlet = midlet;
        lists();
        addCommand(okCmd);
        addCommand(backCmd);
        setCommandListener(this);
    }

    private void lists() {
            okCmd = new Command("Get", Command.OK, 0);
            backCmd = new Command("Back", Command.BACK, 1);
                if (list == null) {                                 
            list = new List("Cities", Choice.IMPLICIT);                                    
            list.append("Kampala", null);
            list.append("Entebbe", null);
            list.append("Mubende", null);
            list.setCommandListener(this);
            list.setSelectedFlags(new boolean[]{false, false, false});                                  
        }

1 个答案:

答案 0 :(得分:1)

WeatherConditionSearch的超类是List。

您在调用super(list3)时尝试调用List构造函数,但javax.microedition.lcdui.List.List没有接受List的构造函数,请参阅API documentation

根据您的描述,您应该调用List(String title, int listType, String[] stringElements, Image[] imageElements)构造函数,并将其传递给城市名称列表。

在开发Java应用时,JavaDocs应该是您的第一个,也就是第0个停止。始终从那里开始。