Android Weather Forecast - Google Weather API - Description

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

Thanks for your advice

Postby rautakari » Wed Feb 03, 2010 1:11 pm

You had a great sample. I used this information to develop an implementation of my own. Could not done it without.
rautakari
Freshman
Freshman
 
Posts: 2
Joined: Wed Feb 03, 2010 1:05 pm

Top

Linki

Postby rautakari » Wed Feb 03, 2010 1:12 pm

And here is the link for the developed site: London Weather
rautakari
Freshman
Freshman
 
Posts: 2
Joined: Wed Feb 03, 2010 1:05 pm

getting the weather forecast by lat and lon

Postby aswani » Tue Mar 09, 2010 6:50 am

Hi all,


i want to get weather forecast by providing latitude and longitude .


Thanks in advance

Aswan
aswani
Junior Developer
Junior Developer
 
Posts: 19
Joined: Tue Feb 09, 2010 12:41 pm

Houston, we have a problem!

Postby robo » Fri Mar 12, 2010 10:05 am

Hi all,

Please help me with this. Have just run this app and have:

java.lang.NoSuchMethodException: org.anddev.android.weatherforecast.views.SingleWeatherInfoView.<init>(android.content.Context, android.util.AttributeSet)

I am new here, so help me please.
robo
Once Poster
Once Poster
 
Posts: 1
Joined: Fri Mar 12, 2010 10:01 am

Postby toobsco42 » Fri Apr 02, 2010 4:01 am

I am trying to make an http request within android but i am getting a Java.IO.FileNotFound exception. This would suggest the url path is incorrect however i tried it in a browser and it works.

Here is my code:
//urlString is the properly formatted string
URL url = new URL(urlString);

/* Get a SAXParser from the SAXPArserFactory. */
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();

/* Get the XMLReader of the SAXParser we created. */
XMLReader xr = sp.getXMLReader();
/* Create a new ContentHandler and apply it to the XML-Reader*/
Handler myHandler = new Handler();
xr.setContentHandler(myHandler);

/* Parse the xml-data from our URL. */


InputStream iStream = url.openStream();
InputSource is = new InputSource(iStream);
xr.parse(is);

The exception is thrown on url.openStream(); All other requests i make are working in android. This includes another request i make within the same activity work. I have already set security permissions in the androidmanifest.xml file. What seems to be the problem?
toobsco42
Freshman
Freshman
 
Posts: 2
Joined: Sun Feb 07, 2010 2:19 am

Postby dhay » Sun Apr 04, 2010 11:20 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.



Hi,

First of wall hello, I am new in the forum. I have been reading it but still not registered.

I am trying to run this tutorial but it is not running. When I modify this:

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

In the main.xml I got NullpointerException:null, My main.xml is like follows:


Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2. <?xml version="1.0" encoding="utf-8"?>
  3. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  4.    android:orientation="vertical"
  5.    android:layout_width="fill_parent"
  6.    android:layout_height="fill_parent"
  7.    android:background="@drawable/weather_background"
  8.    >
  9.     <TableLayout
  10.         android:orientation="horizontal"
  11.         android:layout_width="fill_parent"
  12.         android:layout_height="wrap_content"
  13.         android:stretchColumns="0"
  14.         >
  15.         <TableRow
  16.                         android:layout_width="fill_parent"
  17.                         android:layout_height="wrap_content">
  18.                         <TextView  
  19.                         android:layout_width="wrap_content"
  20.                         android:layout_height="wrap_content"
  21.                         android:text="Usage like: 'City, Country'"
  22.                         android:gravity="left"
  23.                         />
  24.                 <CheckBox android:id="@+id/chk_usecelsius"  
  25.                         android:layout_width="wrap_content"
  26.                                 android:layout_height="wrap_content"
  27.                                 android:text="Use °C (not °F)"
  28.                                 android:gravity="right"
  29.                 />
  30.         </TableRow>
  31.     </TableLayout>
  32.     <TableLayout
  33.         android:orientation="horizontal"
  34.         android:layout_width="fill_parent"
  35.         android:layout_height="wrap_content"
  36.         android:stretchColumns="0"
  37.         >
  38.         <TableRow
  39.                         android:layout_width="fill_parent"
  40.                         android:layout_height="wrap_content">
  41.                          
  42.                         <EditText android:id="@+id/edit_input"
  43.                         android:layout_width="wrap_content"
  44.                         android:layout_height="wrap_content"
  45.                         android:text="Schriesheim, Germany"
  46.                         android:singleLine="true"
  47.                         />
  48.                 <Button android:id="@+id/cmd_submit"
  49.                         android:layout_width="wrap_content"
  50.                         android:layout_height="wrap_content"
  51.                         android:text="OK"
  52.                 />
  53.         </TableRow>
  54.     </TableLayout>
  55.         <agenda.test.SingleWeatherInfoView
  56.     android:id="@+id/weather_today"
  57.     android:orientation="horizontal"
  58.     android:layout_width="fill_parent"
  59.     android:layout_height="wrap_content"
  60.     android:gravity="center_horizontal"
  61.     android:paddingTop="15px"
  62.      />        
  63.  
  64.     <TableLayout
  65.         android:orientation="horizontal"
  66.         android:layout_width="fill_parent"
  67.         android:layout_height="wrap_content"
  68.         android:stretchColumns="0,1,2,3"
  69.         android:paddingTop="15px"
  70.         >
  71.                 <TableRow
  72.                                 android:layout_width="fill_parent"
  73.                                 android:layout_height="wrap_content">
  74.                         <agenda.test.SingleWeatherInfoView
  75.                                 android:id="@+id/weather_1"
  76.                                 android:layout_width="wrap_content"
  77.                                 android:layout_height="wrap_content"
  78.                                 android:gravity="center_horizontal"
  79.                                 android:orientation="vertical"
  80.                                 />
  81.                         <agenda.test.SingleWeatherInfoView
  82.                                 android:id="@+id/weather_2"
  83.                                 android:layout_width="wrap_content"
  84.                                 android:layout_height="wrap_content"
  85.                                 android:gravity="center_horizontal"
  86.                                 android:orientation="vertical"
  87.                                 />
  88.                         <agenda.test.SingleWeatherInfoView
  89.                                 android:id="@+id/weather_3"
  90.                                 android:layout_width="wrap_content"
  91.                                 android:layout_height="wrap_content"
  92.                                 android:gravity="center_horizontal"
  93.                                 android:orientation="vertical"
  94.                                 />
  95.                         <agenda.test.SingleWeatherInfoView
  96.                                 android:id="@+id/weather_4"
  97.                                 android:layout_width="wrap_content"
  98.                                 android:layout_height="wrap_content"
  99.                                 android:gravity="center_horizontal"
  100.                                 android:orientation="vertical"
  101.                                 />
  102.                         </TableRow>
  103.     </TableLayout>
  104. </LinearLayout>
  105.  
  106.  
Parsed in 0.019 seconds, using GeSHi 1.0.8.4


In my case I put the project in agenda.test that's why it is changed. But I tried the same as the original one and still didn't run. This is how SingleWeatherInfoView looks like(I tried the original code changing the method, deleting the MAP also, but didn't run either so I was trying this code that I found here, in this same post, but I don't know if it is correct or not:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. package agenda.test;
  3.  
  4. import java.io.BufferedInputStream;
  5. import java.io.IOException;
  6. import java.io.InputStream;
  7. import java.net.URL;
  8. import java.net.URLConnection;
  9. import java.util.Map;
  10. import android.content.Context;
  11. import android.graphics.Bitmap;
  12. import android.graphics.BitmapFactory;
  13. import android.graphics.Typeface;
  14. import android.util.AttributeSet;
  15. import android.widget.ImageView;
  16. import android.widget.LinearLayout;
  17. import android.widget.TextView;
  18.  
  19. /**
  20.  * The View capable of showing a WeatehrIcon + a Temperature-TextView.
  21.  */
  22. @SuppressWarnings("unused")
  23. public class SingleWeatherInfoView extends LinearLayout {
  24.  
  25.      // ===========================================================
  26.      // Fields
  27.      // ===========================================================
  28.  
  29.      private ImageView myWeatherImageView = null;
  30.      private TextView myTempTextView = null;
  31.      private TextView TempDay =null;
  32.  
  33.      // ===========================================================
  34.      // Constructors
  35.      // ===========================================================
  36.  
  37.      public SingleWeatherInfoView(Context context) {
  38.           super(context);
  39.      }
  40.  
  41.      public SingleWeatherInfoView(Context context, AttributeSet attrs) {
  42.           super(context, attrs);
  43.           /* Setup the ImageView that will show weather-icon. */
  44.           this.myWeatherImageView = new ImageView(context);
  45.           this.myWeatherImageView.setImageDrawable(getResources().getDrawable(R.drawable.dunno));
  46.  
  47.           /* Setup the textView that will show the temperature. */
  48.           this.myTempTextView = new TextView(context);
  49.           this.myTempTextView.setText("?");
  50.           this.myTempTextView.setTextSize(16);
  51.           this.myTempTextView.setTextColor(0xFF000000);
  52.           this.myTempTextView.setTypeface(Typeface.create("Tahoma", Typeface.BOLD));
  53.           /* Setup the textView that will show the day of forecast. */
  54.           this.TempDay = new TextView(context);
  55.           this.TempDay.setText("");
  56.           this.TempDay.setTextSize(16);
  57.           this.TempDay.setTextColor(0xFF000000);
  58.           this.TempDay.setTypeface(Typeface
  59.                     .create("Tahoma", Typeface.BOLD));
  60.           /* Add child views to this object. */
  61.           this.addView(this.myWeatherImageView, new LinearLayout.LayoutParams(
  62.                     LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));                                                            
  63.           this.addView(this.myTempTextView, new LinearLayout.LayoutParams(
  64.                     LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
  65.           this.addView(this.TempDay, new LinearLayout.LayoutParams(
  66.                           LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
  67.      }
  68.  
  69.      // ===========================================================
  70.      // Getter & Setter
  71.      // ===========================================================
  72.  
  73.      public void reset() {
  74.           this.myWeatherImageView.setImageDrawable(getResources().getDrawable(R.drawable.dunno));
  75.           this.myTempTextView.setText("?");
  76.           this.TempDay.setText("");
  77.      }
  78.  
  79.      /** Sets the Child-ImageView of this to the URL passed. */
  80.      public void setRemoteImage(URL aURL) {
  81.           try {
  82.                URLConnection conn = aURL.openConnection();
  83.                conn.connect();
  84.                InputStream is = conn.getInputStream();
  85.                BufferedInputStream bis = new BufferedInputStream(is);
  86.                Bitmap bm = BitmapFactory.decodeStream(bis);
  87.                bis.close();
  88.                is.close();
  89.                this.myWeatherImageView.setImageBitmap(bm);
  90.           } catch (IOException e) {
  91.                /* Reset to 'Dunno' on any error. */
  92.                this.myWeatherImageView.setImageDrawable(getResources()
  93.                          .getDrawable(R.drawable.dunno));
  94.           }
  95.      }
  96.  
  97.      public void setTempCelcius(int aTemp) {
  98.           this.myTempTextView.setText("" + aTemp + " °C");
  99.      }
  100.  
  101.      public void setTempFahrenheit(int aTemp) {
  102.           this.myTempTextView.setText("" + aTemp + " °F");
  103.      }
  104.  
  105.      public void setTempFahrenheitMinMax(int aMinTemp, int aMaxTemp) {
  106.           this.myTempTextView.setText("" + aMinTemp + "/" + aMaxTemp + " °F");
  107.      }
  108.  
  109.      public void setTempCelciusMinMax(int aMinTemp, int aMaxTemp) {
  110.           this.myTempTextView.setText("" + aMinTemp + "/" + aMaxTemp + " °C");
  111.      }
  112.  
  113.      public void setTempString(String aTempString) {
  114.           this.myTempTextView.setText(aTempString);
  115.      }
  116.      
  117.      public void setDayofWeek(String dayofWeek) {
  118.                 this.TempDay.setText("" +dayofWeek);
  119.         }
  120.    
  121. }
  122.  
Parsed in 0.083 seconds, using GeSHi 1.0.8.4


I was trying to modify by myself the code, but I don't really know how to put the SingleWeatherInfoView in the main, it never finds the class.


Here I upload all the project (I commented the R.id.weather_1 and so on in the Weatherforecast.java to be able to compile, because it did not find them).

Thanks in advance,

dhay
Attachments
Copy of testAgenda.rar
Scanned with Avira Antivir Personal.
(195.31 KiB) Downloaded 37 times
dhay
Once Poster
Once Poster
 
Posts: 1
Joined: Sun Apr 04, 2010 11:06 am

Top

NULL Pointer Exception

Postby Dev » Thu Apr 15, 2010 4:53 am

I am getting NULL Pointer Exception while calling openStream APIs for google weather. I did give INTERNET permission in manifest file but still getting NULL pointer exception. Please can you help me.
Dev
Freshman
Freshman
 
Posts: 6
Joined: Fri Mar 26, 2010 11:05 am

Re: Android Weather Forecast - Google Weather API - Descript

Postby vivek_goel » Thu Jul 29, 2010 2:54 pm

Thanks alottttttttttttttttt Shalini...
u r owsome.
u made my day.
now its working fine.
vivek_goel
Freshman
Freshman
 
Posts: 2
Joined: Wed Jul 14, 2010 10:52 am

Top
Previous

Return to Advanced Tutorials

Who is online

Users browsing this forum: No registered users and 2 guests