【问题标题】:Weather Forecast program天气预报程序
【发布时间】:2012-11-25 13:31:42
【问题描述】:

我正在做一个“天气预报”项目,信息来自this static URL。我必须获得城市列表及其条件。例如,当我输入 Tokyo 时,它应该显示:

Tokyo, Japan#14#Cloudy ##

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

输出格式为纯文本:

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

它给了我错误:

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

这是我的代码:

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

如何解决无效布局错误?

【问题讨论】:

  • 您的字符串 url 使用的是 ` 而不是 ",可能就是这样。将 String ` url = ` http:// 更改为 String url = `http://
  • @NiravRanpara Invalid layout of java.lang.String at value # # Java Runtime Environment 检测到致命错误:# # Internal Error (javaClasses.cpp:129), pid=6464, tid=7052 # 致命错误:预加载类的布局无效 # # JRE 版本:7.0_09-b05 # Java VM: Java HotSpot(TM) Client VM (23.5-b02 mixed mode windows-x86 ) # 无法写入核心转储。默认情况下,在 Windows 的客户端版本上不启用小型转储#
  • 请把有问题的代码不要放在评论中
  • @user1810737 是字符串 url(我这里写错了)
  • 你为什么用`而不是"?

标签: android android-widget weather


【解决方案1】:

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

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

"url" 前面的 ` 弄乱了你的字符串,并在 http: 之后使所有内容成为注释,因为 //.

【讨论】:

  • stackoverflow 消息布局完全改变了`,因为它将文本更改为代码,但我希望你能理解我的回答。
猜你喜欢
  • 1970-01-01
  • 2011-05-16
  • 2013-06-22
  • 2016-06-10
  • 1970-01-01
  • 1970-01-01
  • 2015-05-06
  • 2019-04-15
  • 1970-01-01
相关资源
最近更新 更多