Reputation: 35
I am working on a project "Weather forecast" and information is given from this static URL. I have to obtain the list of cities with their conditions. For example, when I type Tokyo, it should display this:
Tokyo, Japan#14#Cloudy ##
I have also created the ArrayList
with the list of cities. I have done the layout xml file.
The output format is text plain:
(\n)
(##)
It gives me errors:
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
This is my code:
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();
}
How do I resolve the invalid layout error?
Upvotes: 1
Views: 874
Reputation: 234
Change
String " `
url =http://myexample.info/?cities `
to
String url = "http://myexample.info/?cities";
The ` in front of "url" is messing up your string and makes everything after http: a comment, because of the //.
Upvotes: 1