我正在开展“天气预报”项目,信息来自this static URL。我必须获得符合其条件的城市列表。例如,当我输入东京时,它应该显示:
Tokyo, Japan#14#Cloudy ##
我还使用城市列表创建了ArrayList
。我已经完成了布局xml文件。
输出格式为text plain:
(\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();
}
如何解决无效的布局错误?
答案 0 :(得分:1)
更改
字符串“`
url = http://myexample.info/?cities`
到
String url =“http://myexample.info/?cities”;
在“url”前面的`弄乱了你的字符串并在http:评论之后做了所有事情,因为//.