首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >天气预报程序

天气预报程序
EN

Stack Overflow用户
提问于 2012-12-07 11:11:58
回答 1查看 848关注 0票数 1

我正在做一个名为“天气预报”的项目,信息来自这个静态URL。我要弄到一张列有他们的条件的城市名单。例如,当我输入东京时,它应该显示如下:

代码语言:javascript
复制
Tokyo, Japan#14#Cloudy ##

我还创建了包含城市列表的ArrayList。我已经完成了布局xml文件。

输出格式是纯文本:

  • 每个输出行都以换行符(\n)结束。
  • 流总是以包含两个符号(##)的一行结束。

它给我带来了错误:

代码语言:javascript
复制
Invalid layout of java.lang.String at value

A fatal error has been detected by the Java Runtime Environment:

Internal Error (javaClasses.cpp:129), pid=6464, tid=7052
fatal error: Invalid layout of preloaded class

这是我的密码:

代码语言:javascript
复制
import android.app.Activity;
import android.os.Bundle;

public class Meteo extends Activity{

        @Override
    protected void onCreate(Bundle savedInstanceState) { {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.meteo);

        String url = `http://myexample.info/?cities`;
        // Weather information
        String weather = "Tokyo, Japan#14#Cloudy ##";
        // Get the city name
        String city = url.substring(url.indexOf("?") + 1).trim();
        System.out.println(city);
        // Check the weather of the city: 14#Cloudy
        // Remove city name
        // Remove last #
        if (weather.toLowerCase().contains(city.toLowerCase())) {
            // Get condition: 
            String condition = weather.substring(weather.indexOf("#") + 1,
                    weather.length() - 2);
            System.out.println(condition);
            // Split with # sign and you have a list of conditions
            String[] information = condition.split("#");
            for (int i = 0; i < information.length; i++) {
                System.out.println(information[i]);
            }
        }

            @Override

            protected void onPause() {
                // TODO Auto-generated method stub
                super.onPause();
            }

如何解决无效的布局错误?

EN

回答 1

Stack Overflow用户

发布于 2012-12-07 11:21:15

更改字符串“` url =http://myexample.info/?cities

字符串url = "http://myexample.info/?cities"

"url“前面的‘是搞乱了您的字符串,并在http: a注释之后进行了所有操作,这是因为//。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13761940

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档