简体   繁体   中英

Weather app: J2me constructor

I have a problem with a weather app am working on. The constructor is supposed to create a list but when the app runs, it just shows a blank screen.

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)

//class with constructor

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!
    }

//class where I want to create a list of my local cites

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

Superclass for WeatherConditionSearch is List.

You're trying to invoke the List constructor when you call super(list3) , but javax.microedition.lcdui.List.List doesn't have a constructor that accepts a List, see API documentation .

From what you describe, you rather should call the List(String title, int listType, String[] stringElements, Image[] imageElements) constructor, passing it a list of city names.

The JavaDocs should be your first, nay, your zeroth stop when developing Java apps. Always start there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM