问答详情
源自:5-3 格式化输出天气预报结果

为什么我到输入城市的那一步就报错

package com.imooc.weather;

import com.imooc.weather.impl.WeatherUtilsImpl;
import sun.plugin.dom.exception.BrowserNotSupportedException;

import java.util.List;
import java.util.Scanner;

public class Application {
    public static void main(String[] args) {
        System.out.println("查询最近天气预报");
        System.out.println("输入1:查询未来24小时天气预报");
        System.out.println("输入2:查询未来3天天气预报");
        System.out.println("输入3:查询未来7天天气预报");
        System.out.print("请输入您的选择:");
        Scanner scanner= new Scanner(System.in);
        int i= scanner.nextInt();
        System.out.println("用户输入数字"+i);
        if (i==1){
            System.out.println("请输入城市名称查询为24小时天气预报");
            String city= scanner.next();
            WeatherUtils weatherUtils =new WeatherUtilsImpl();
            List<HourWeather> weatherList = weatherUtils.w24h("6196c9db162949e78158039af608da0c",city);//有问题
            System.out.println(weatherList);
            if (weatherList.size()==0){
                System.out.println("抱歉,未收录您查询的城市天气数据");
            }else {
                for (HourWeather hourWeather: weatherList){
                    String template= "%s月%s日%s时|%s|%s|%s|%s℃";
                    String row= String.format(template,new String[]{
                            hourWeather.getMonth(),
                            hourWeather.getDay(),
                            hourWeather.getHour(),
                            hourWeather.getWindDirection(),
                            hourWeather.getWindPower(),
                            hourWeather.getTemperature(),
                    });
                    System.out.println(row);


提问者:慕侠1366386 2022-04-25 21:02

个回答

  • weixin_慕设计7170140
    2022-05-27 18:05:38

    把最上面自动引用的的包删除了