1

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

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});                                  
        }
4

1 回答 1

1

WeatherConditionSearch 的超类是 List。

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

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

JavaDocs应该是您开发 Java 应用程序时的第一站,不,是您的零站。总是从那里开始。

于 2012-07-02T07:16:54.990 回答