Android Weather Forecast - Google Weather API - Description

Tutorials with advanced 'difficulty' and more Lines of Code.

Postby MrSnowflake » Tue Nov 18, 2008 3:49 pm

Something is wrong with your layout xml, SingleWheatherInfoView can't be found. That's what you callstack says.
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Top

Postby jeffy2010 » Tue Nov 18, 2008 4:00 pm

Yes MrSnowflake..
When I open my main.xml on the layout view, it says the following

NoSuchMethodException:org.anddev.android.weatherforecast.views.SingleWeatherInfoView.<init>(android.content.Context, android.util.AttributeSet)
jeffy2010
Freshman
Freshman
 
Posts: 5
Joined: Tue Nov 18, 2008 3:28 pm

Postby jeffy2010 » Tue Nov 18, 2008 4:14 pm

Hi MrSnowflake.

I have resolved the issue and the app is running fine now.

The super of SingleWeatherInfoView which was extending the LinearLayout class had a parameter of "Map", which is not available in the LinearLayout.

Removed the Map, and its working fine.

SingleWeatherInfoView.java - line 41
public SingleWeatherInfoView(Context context, AttributeSet attrs,
Map inflateParams) {
super(context, attrs, inflateParams);

Thank you so much.
jeffy2010
Freshman
Freshman
 
Posts: 5
Joined: Tue Nov 18, 2008 3:28 pm

Postby mlw4428 » Sun Nov 23, 2008 11:49 pm

I sorta stumbled across this page and while it sorta doesn't relate to Android development, it is inline with the OP's subject.

I have a library I created (it's open source) that does the similar thing for .NET. If you're interested you can visit my personal site (which I won't give out to keep from making it seem like I' m spamming). You can get it by messaging me or emailing me at mlw4428 at gmail dot com.

And I certainly can feel you on the XML layout..

You can also find it by searching for GWPLNET on sourceforge. But yeah, great article, just wished I found it sooner :P
mlw4428
Once Poster
Once Poster
 
Posts: 1
Joined: Sun Nov 23, 2008 11:45 pm

Re: Android Weather Forecast - Google Weather API - Descript

Postby stanimir » Tue Dec 02, 2008 10:45 pm

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. Button cmd_submit = (Button)findViewById(R.id.cmd_submit);
  2.  
  3.                 cmd_submit.setOnClickListener(new OnClickListener(){
  4.  
  5.                         @Override
  6.  
  7.                         public void onClick(View arg0) {
  8.  
  9.                                 URL url;
  10.  
  11.                                 try {
  12.  
  13.                                         /* Get what user typed to the EditText. */                                     
  14.  
  15.                                         String cityParamString =
  16.  
  17.                                                 ((EditText)findViewById(R.id.edit_input))
  18.  
  19.                                                         .getText().toString();
  20.  
  21.                                         String queryString =
  22.  
  23.                                                 "http://www.google.com/ig/api?weather="
  24.  
  25.                                                         + cityParamString;
  26.  
  27.                                         /* Replace blanks with HTML-Equivalent. */
  28.  
  29.                                         url = new URL(queryString.replace(" ", "%20"));
  30.  
  31.  
  32.  
  33.                                         /* Get a SAXParser from the SAXPArserFactory. */
  34.  
  35.                                         SAXParserFactory spf = SAXParserFactory.newInstance();
  36.  
  37.                                         SAXParser sp = spf.newSAXParser();
  38.  
  39.                                        
  40.  
  41.                                         /* Get the XMLReader of the SAXParser we created. */
  42.  
  43.                                         XMLReader xr = sp.getXMLReader();
  44.  
  45.                                        
  46.  
  47.                                         /* Create a new ContentHandler and apply it to the XML-Reader*/
  48.  
  49.                                         GoogleWeatherHandler gwh = new GoogleWeatherHandler();
  50.  
  51.                                         xr.setContentHandler(gwh);
  52.  
  53.                                        
  54.  
  55.                                         /* Parse the xml-data our URL-call returned. */
  56.  
  57.                                         xr.parse(new InputSource(url.openStream()));
  58.  
  59.  
  60.  
  61.                                         /* Our Handler now provides the parsed weather-data to us. */
  62.  
  63.                                         WeatherSet ws = gwh.getWeatherSet();
  64.  
  65.                                        
  66.  
  67.                                         /* Update the SingleWeatherInfoView with the parsed data. */
  68.  
  69.                                         updateWeatherInfoView(R.id.weather_today, ws.getWeatherCurrentCondition());
  70.  
  71.                                        
  72.  
  73.                                         updateWeatherInfoView(R.id.weather_1, ws.getWeatherForecastConditions().get(0));
  74.  
  75.                                         updateWeatherInfoView(R.id.weather_2, ws.getWeatherForecastConditions().get(1));
  76.  
  77.                                         updateWeatherInfoView(R.id.weather_3, ws.getWeatherForecastConditions().get(2));
  78.  
  79.                                         updateWeatherInfoView(R.id.weather_4, ws.getWeatherForecastConditions().get(3));
  80.  
  81.                                        
  82.  
  83.                                 } catch (Exception e) {
  84.  
  85.                                         resetWeatherInfoViews();
  86.  
  87.                                         Log.e(DEBUG_TAG, "WeatherQueryError", e);
  88.  
  89.                                 }
  90.  
  91.                         }
  92.  
  93.                 });
Parsed in 0.036 seconds, using GeSHi 1.0.8.4



I have database with cities from http://www.geonames.org/export/ and use SAX parser in Java Crawler to write in database weather for each city but the SAX parser have encoding problem with weather link like this:
http://www.google.bg/ig/api?weather=Almería,ES&hl=en

the xml page is:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <xml_api_reply version="1">
  2.  
  3. <weather module_id="0" tab_id="0">
  4.  
  5. <forecast_information>
  6.  
  7. <city data="Almeria, AL"/>
  8.  
  9. <postal_code data="Almería,ES"/> <!-- -in this line the SAX parser break -->
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


I try to fix this with setEncoding to InputSource but the problem exist :)

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. java.io.UTFDataFormatException: Invalid byte 2 of 3-byte UTF-8 sequence.
  2.  
  3.         at org.apache.xerces.impl.io.UTF8Reader.invalidByte(Unknown Source)
  4.  
  5.         at org.apache.xerces.impl.io.UTF8Reader.read(Unknown Source)
  6.  
  7.         at org.apache.xerces.impl.XMLEntityScanner.load(Unknown Source)
  8.  
  9.         at org.apache.xerces.impl.XMLEntityScanner.scanLiteral(Unknown Source)
  10.  
  11.         at org.apache.xerces.impl.XMLScanner.scanAttributeValue(Unknown Source)
  12.  
  13.         at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanAttribute(Unknown Source)
  14.  
  15.         at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown Source)
  16.  
  17.         at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
  18.  
  19.         at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
  20.  
  21.         at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
  22.  
  23.         at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
  24.  
  25.         at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
  26.  
  27.         at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
Parsed in 0.034 seconds, using GeSHi 1.0.8.4



this is my function

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.     public void parseDocument(String queryString) {
  2.  
  3. //queryString = http://www.google.bg/ig/api?weather=Almería,ES&hl=en
  4.  
  5.  
  6.  
  7.         //get a factory
  8.  
  9.         SAXParserFactory spf = SAXParserFactory.newInstance();
  10.  
  11.         try {
  12.  
  13.             //get a new instance of parser
  14.  
  15.             SAXParser sp = spf.newSAXParser();
  16.  
  17.             // sp.parse(queryString,this);
  18.  
  19.  
  20.  
  21.             URL url = new URL(queryString);
  22.  
  23.             /* Get the XMLReader of the SAXParser we created. */
  24.  
  25.             XMLReader xr = sp.getXMLReader();
  26.  
  27.             xr.setContentHandler(this);
  28.  
  29.  
  30.  
  31.             /* Parse the xml-data our URL-call returned. */
  32.  
  33.             InputSource src = new InputSource(url.openStream());
  34.  
  35.             src.setEncoding("UTF-8");
  36.  
  37.             xr.parse(src);
Parsed in 0.035 seconds, using GeSHi 1.0.8.4
stanimir
Freshman
Freshman
 
Posts: 2
Joined: Tue Dec 02, 2008 10:27 pm

Postby plusminus » Tue Dec 02, 2008 11:11 pm

The reason is very probably the "í" in the response.

If you search without the ´ thing it works with me:

http://www.google.bg/ig/api?weather=Almeria,ES&hl=en
// instead of
http://www.google.bg/ig/api?weather=Almería,ES&hl=en

Best Regards,
Nicolas
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Top

Postby stanimir » Wed Dec 03, 2008 9:10 am

This is not the decision of the problem SAX parser do not work with UTF-8..
I don`t have the table with Google name of the city like Almeria and will try to use DOM Parser
stanimir
Freshman
Freshman
 
Posts: 2
Joined: Tue Dec 02, 2008 10:27 pm

Postby AJ Quick » Mon Dec 29, 2008 6:17 am

jeffy2010 wrote:Hi MrSnowflake.

I have resolved the issue and the app is running fine now.

The super of SingleWeatherInfoView which was extending the LinearLayout class had a parameter of "Map", which is not available in the LinearLayout.

Removed the Map, and its working fine.

SingleWeatherInfoView.java - line 41
public SingleWeatherInfoView(Context context, AttributeSet attrs,
Map inflateParams) {
super(context, attrs, inflateParams);

Thank you so much.


I wanted to test this program out.. but I am now having the same error.

Removing Map doesn't fix it the same way it did for you.
AJ Quick
Junior Developer
Junior Developer
 
Posts: 16
Joined: Wed Nov 19, 2008 8:16 pm

Thanks for the info

Postby weatherdoll » Wed Jan 07, 2009 2:00 am

Just wanted to say thanks for providing the info.
It gave me the push needed to start on my own little google weather feed app in Flash
weatherdoll
Freshman
Freshman
 
Posts: 2
Joined: Mon Jan 05, 2009 9:36 pm

Postby weatherdoll » Wed Jan 07, 2009 2:04 am

I used PHP as the proxy,
Which loads the xml AND saves a copy of the XML locally on the harddrive to prevent a flood of requests hitting google for the same weather info. It stores the local copy for 1 hour (essentally matching the Yahoo XML feed requirements).

I put most of my code and a current running sample on my website
See:
Googles weather api

Now I will start working on the client interface and get a few versions up.
weatherdoll
Freshman
Freshman
 
Posts: 2
Joined: Mon Jan 05, 2009 9:36 pm

Postby EverYoung124 » Tue Feb 17, 2009 8:54 pm

plusminus, Thank you very much for the tutorial. It is very helpful. I want to report a problem when I use it on SDK1.1-r1 and provide a solution.

First I used the source code and added the INTERNET use-permission. After installing, an error occurs when I hit the button.
E/WeatherForecaster( 419): WeatherQuerryError
E/WeatherForecaster( 419): java.io.FileNotFoundException: http://www.google.com/ig/api?weather=Sc ... %20Germany
E/WeatherForecaster( 419): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1040)
E/WeatherForecaster( 419): at java.net.URL.openStream(URL.java:664)


However I can still get the xml file from a browser. After some testing and googling, I find that the program does not like the weather API url and I don't know why it happens. So I switched to HttpClient to open the url. What I did is replace the parse line
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. xr.parse(new InputSource(url.openStream()));
Parsed in 0.035 seconds, using GeSHi 1.0.8.4

with the following
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.                      /* Use HTTPClient to deal with the URL */
  2.                                 HttpClient httpclient = new DefaultHttpClient();
  3.                                 HttpGet httpget = new HttpGet(queryString.replace(" ", "%20"));
  4.                                 Log.d(DEBUG_TAG, "executing request " + httpget.getURI());
  5.                                 // create a response handler
  6.                                 ResponseHandler<String> responseHandler = new BasicResponseHandler();
  7.                                 String responseBody = httpclient.execute(httpget, responseHandler);
  8.                                 // Log.d(DEBUG_TAG, "response from httpclient:n "+responseBody);
  9.                                
  10.                                 ByteArrayInputStream is = new ByteArrayInputStream(responseBody.getBytes());
  11.                                 xr.parse(new InputSource(is));
  12.                                 Log.d(DEBUG_TAG, "parse complete");
  13.                                 // parse complete
Parsed in 0.038 seconds, using GeSHi 1.0.8.4


Then the problem goes away. Hope it might help some people.
Hang on.
EverYoung124
Freshman
Freshman
 
Posts: 2
Joined: Mon Dec 08, 2008 10:13 pm

About the Weatherbug API

Postby marmozsdx » Fri May 15, 2009 9:42 pm

Hi guys,

I'm new to this site, and I just happen to come across this forum tutorial.

I did find it interesting that there were some issues with the Google API not accepting Lat. and Long., so I did a bit of research on the web and found out about this API from Weatherbug.com. Apparently developers need only register, confirm their account, and they are given a license to use the API.

Their API seems a lot more robust, and it allows for Lat./Long. search, so the GPS functionality can be integrated in a single step.

Here's the link to the API info: http://weather.weatherbug.com/desktop-weather/api.html
and here's a description of the API functionality: http://api.wxbug.net/help.html#compactdescr

I hope it helps you guys. I have not started work on this tutorial, but I will get started and try to implement the Weatherbug API.

Thanks for all the tutorials and the collaboration of all of you.

Francisco
marmozsdx
Once Poster
Once Poster
 
Posts: 1
Joined: Fri May 15, 2009 9:34 pm

Weather Forecasting (1.1 V)

Postby Shalni » Thu May 28, 2009 10:11 am

Hi everybody,

Here is the weather forecasting code working on sdk 1.1 as there were some changes to be made inorder to work in 1.1 version from the original code. Hope this helps.

Thank you.
Attachments
WeatherForecasting.zip
(181.36 KiB) Downloaded 892 times
Shalni
Junior Developer
Junior Developer
 
Posts: 17
Joined: Wed Apr 29, 2009 6:31 am

Postby armstrong » Wed Sep 30, 2009 8:59 am

I have this problem after entering the xml code into the main.xml.
How can i solve this problem so that my layout will appears ?
Attachments
notfound.jpg
Notfoundexception
notfound.jpg (489.07 KiB) Viewed 9151 times
armstrong
Once Poster
Once Poster
 
Posts: 1
Joined: Mon Sep 28, 2009 3:57 am

Postby suman291857 » Mon Nov 09, 2009 4:31 pm

You can infact use google weather API to accept longitude,latitude
Have a look at this post
http://insightmed.eu/blog/2008/programm ... er-api-php
But i think we have to be carefull abt using google API it as its not official
Thanks for tutorial..It was very usefull...
suman291857
Freshman
Freshman
 
Posts: 2
Joined: Sat Sep 12, 2009 10:45 am

Top
PreviousNext

Return to Advanced Tutorials

Who is online

Users browsing this forum: No registered users and 8 guests