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

来源:5-3 格式化输出天气预报结果

慕侠1366386

2022-04-25 21:02

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


写回答 关注

1回答

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

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

Java入门第二季 升级版

课程升级!以终为始告别枯燥,在开发和重构中体会Java面向对象编程的奥妙

530553 学习 · 6091 问题

查看课程

相似问题