Advertisement
Guest User

Untitled

a guest
Mar 7th, 2014
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. // this is model class
  3.  
  4. package ali.arshad.soomro.openweathermap.androidsdk;
  5.  
  6. import java.io.Serializable;
  7. import java.util.ArrayList;
  8. import java.util.List;
  9.  
  10. import com.google.gson.annotations.SerializedName;
  11.  
  12. public class WeatherForecastInfo implements Serializable {
  13.  
  14.     /**
  15.      *
  16.      */
  17.     private static final long serialVersionUID = 1L;
  18.     private String cod;
  19.     private Double message;
  20.     private City city;
  21.     private Integer cnt;
  22.     private ListItem listItem;
  23.     private List<ListItem> list = new ArrayList<ListItem>();
  24.    
  25.     /**
  26.      * @return the listItem
  27.      */
  28.     public ListItem getListItem() {
  29.         return listItem;
  30.     }
  31.  
  32.     /**
  33.      * @param listItem the listItem to set
  34.      */
  35.     public void setListItem(ListItem listItem) {
  36.         this.listItem = listItem;
  37.     }
  38.  
  39.  
  40.     public String getCod() {
  41.         return cod;
  42.     }
  43.  
  44.     public void setCod(String cod) {
  45.         this.cod = cod;
  46.     }
  47.  
  48.     public Double getMessage() {
  49.         return message;
  50.     }
  51.  
  52.     public void setMessage(Double message) {
  53.         this.message = message;
  54.     }
  55.  
  56.     public City getCity() {
  57.         return city;
  58.     }
  59.  
  60.     public void setCity(City city) {
  61.         this.city = city;
  62.     }
  63.  
  64.     public Integer getCnt() {
  65.         return cnt;
  66.     }
  67.  
  68.     public void setCnt(Integer cnt) {
  69.         this.cnt = cnt;
  70.     }
  71.  
  72.     public List<ListItem> getList() {
  73.         return list;
  74.     }
  75.  
  76.     public void setList(List<ListItem> list) {
  77.         this.list = list;
  78.     }
  79.  
  80.     public class City implements Serializable {
  81.         /**
  82.          *
  83.          */
  84.         private static final long serialVersionUID = 1L;
  85.         private Integer id;
  86.         private String name;
  87.         @SerializedName("coord")
  88.         private Coordinates coordinates;
  89.         private String country;
  90.         private Integer population;
  91.         private Sys sys;
  92.  
  93.         public Integer getId() {
  94.             return id;
  95.         }
  96.  
  97.         public void setId(Integer id) {
  98.             this.id = id;
  99.         }
  100.  
  101.         public String getName() {
  102.             return name;
  103.         }
  104.  
  105.         public void setName(String name) {
  106.             this.name = name;
  107.         }
  108.  
  109.         public Coordinates getCoordinates() {
  110.             return coordinates;
  111.         }
  112.  
  113.         public void setCoordinates(Coordinates coordinates) {
  114.             this.coordinates = coordinates;
  115.         }
  116.  
  117.         public String getCountry() {
  118.             return country;
  119.         }
  120.  
  121.         public void setCountry(String country) {
  122.             this.country = country;
  123.         }
  124.  
  125.         public Integer getPopulation() {
  126.             return population;
  127.         }
  128.  
  129.         public void setPopulation(Integer population) {
  130.             this.population = population;
  131.         }
  132.  
  133.         public Sys getSys() {
  134.             return sys;
  135.         }
  136.  
  137.         public void setSys(Sys sys) {
  138.             this.sys = sys;
  139.         }
  140.  
  141.         public class Coordinates implements Serializable {
  142.             /**
  143.              *
  144.              */
  145.             private static final long serialVersionUID = 1L;
  146.             @SerializedName("lon")
  147.             private Double longitude;
  148.             @SerializedName("lat")
  149.             private Double latitude;
  150.  
  151.             public Double getLongitude() {
  152.                 return longitude;
  153.             }
  154.  
  155.             public void setLongitude(Double longitude) {
  156.                 this.longitude = longitude;
  157.             }
  158.  
  159.             public Double getLatitude() {
  160.                 return latitude;
  161.             }
  162.  
  163.             public void setLatitude(Double latitude) {
  164.                 this.latitude = latitude;
  165.             }
  166.         }
  167.  
  168.         public class Sys implements Serializable {
  169.             /**
  170.              *
  171.              */
  172.             private static final long serialVersionUID = 1L;
  173.             private Integer population;
  174.  
  175.             public Integer getPopulation() {
  176.                 return population;
  177.             }
  178.  
  179.             public void setPopulation(Integer population) {
  180.                 this.population = population;
  181.             }
  182.         }
  183.     }
  184.  
  185.     public class ListItem implements Serializable {
  186.         /**
  187.          *
  188.          */
  189.         private static final long serialVersionUID = 1L;
  190.         @SerializedName("dt")
  191.         private Long dateTime;
  192.         @SerializedName("temp")
  193.         private Temperature temperature;
  194.         private Double pressure;
  195.         private Integer humidity;
  196.         private List<Weather> weather = new ArrayList<Weather>();
  197.         private Double speed;
  198.         @SerializedName("deg")
  199.         private Integer degree;
  200.         private Integer clouds;
  201.  
  202.         public Long getDateTime() {
  203.             return dateTime;
  204.         }
  205.  
  206.         public void setDateTime(Long dateTime) {
  207.             this.dateTime = dateTime;
  208.         }
  209.  
  210.         public Temperature getTemperature() {
  211.             return temperature;
  212.         }
  213.  
  214.         public void setTemperature(Temperature temperature) {
  215.             this.temperature = temperature;
  216.         }
  217.  
  218.         public Double getPressure() {
  219.             return pressure;
  220.         }
  221.  
  222.         public void setPressure(Double pressure) {
  223.             this.pressure = pressure;
  224.         }
  225.  
  226.         public Integer getHumidity() {
  227.             return humidity;
  228.         }
  229.  
  230.         public void setHumidity(Integer humidity) {
  231.             this.humidity = humidity;
  232.         }
  233.  
  234.         public List<Weather> getWeather() {
  235.             return weather;
  236.         }
  237.  
  238.         public void setWeather(List<Weather> weather) {
  239.             this.weather = weather;
  240.         }
  241.  
  242.         public Double getSpeed() {
  243.             return speed;
  244.         }
  245.  
  246.         public void setSpeed(Double speed) {
  247.             this.speed = speed;
  248.         }
  249.  
  250.         public Integer getDegree() {
  251.             return degree;
  252.         }
  253.  
  254.         public void setDegree(Integer degree) {
  255.             this.degree = degree;
  256.         }
  257.  
  258.         public Integer getClouds() {
  259.             return clouds;
  260.         }
  261.  
  262.         public void setClouds(Integer clouds) {
  263.             this.clouds = clouds;
  264.         }
  265.  
  266.         public class Temperature implements Serializable {
  267.             /**
  268.              *
  269.              */
  270.             private static final long serialVersionUID = 1L;
  271.             private Double day;
  272.             private Double min;
  273.             private Double max;
  274.             private Double night;
  275.             @SerializedName("eve")
  276.             private Double evening;
  277.             @SerializedName("morn")
  278.             private Double morning;
  279.  
  280.             public Double getDay() {
  281.                 return day;
  282.             }
  283.  
  284.             public void setDay(Double day) {
  285.                 this.day = day;
  286.             }
  287.  
  288.             public Double getMin() {
  289.                 return min;
  290.             }
  291.  
  292.             public void setMin(Double min) {
  293.                 this.min = min;
  294.             }
  295.  
  296.             public Double getMax() {
  297.                 return max;
  298.             }
  299.  
  300.             public void setMax(Double max) {
  301.                 this.max = max;
  302.             }
  303.  
  304.             public Double getNight() {
  305.                 return night;
  306.             }
  307.  
  308.             public void setNight(Double night) {
  309.                 this.night = night;
  310.             }
  311.  
  312.             public Double getEvening() {
  313.                 return evening;
  314.             }
  315.  
  316.             public void setEvening(Double evening) {
  317.                 this.evening = evening;
  318.             }
  319.  
  320.             public Double getMorning() {
  321.                 return morning;
  322.             }
  323.  
  324.             public void setMorning(Double morning) {
  325.                 this.morning = morning;
  326.             }
  327.         }
  328.  
  329.         public class Weather implements Serializable {
  330.             /**
  331.              *
  332.              */
  333.             private static final long serialVersionUID = 1L;
  334.             private Integer id;
  335.             private String main;
  336.             private String description;
  337.             private String icon;
  338.  
  339.             public Integer getId() {
  340.                 return id;
  341.             }
  342.  
  343.             public void setId(Integer id) {
  344.                 this.id = id;
  345.             }
  346.  
  347.             public String getMain() {
  348.                 return main;
  349.             }
  350.  
  351.             public void setMain(String main) {
  352.                 this.main = main;
  353.             }
  354.  
  355.             public String getDescription() {
  356.                 return description;
  357.             }
  358.  
  359.             public void setDescription(String description) {
  360.                 this.description = description;
  361.             }
  362.  
  363.             public String getIcon() {
  364.                 return icon;
  365.             }
  366.  
  367.             public void setIcon(String icon) {
  368.                 this.icon = icon;
  369.             }
  370.         }
  371.     }
  372. }
  373.  
  374. // and in my DemoActivity class
  375.  
  376.  
  377. protected List<WeatherForecastInfo.ListItem.Weather> list = null;
  378. protected ArrayAdapter<WeatherForecastInfo.ListItem.Weather> adapter = null;
  379.  
  380. //and in onCreate I have
  381.  
  382. mapUtil = WeatherUtil.newInstance();
  383.         button.setOnClickListener(new OnClickListener() {
  384.  
  385.             @Override
  386.             public void onClick(View v) {
  387.                 // TODO Auto-generated method stub
  388.                 new AsyncTask<String, Void, WeatherForecastInfo>() {
  389.                     @Override
  390.                     protected void onPreExecute() {
  391.                         progressDialog = new ProgressDialog(DemoActivity.this);
  392.                         progressDialog.setTitle("Wait...");
  393.                         progressDialog.setMessage("Data is being loaded...");
  394.                         progressDialog.show();
  395.                     }
  396.  
  397.                     @Override
  398.                     protected WeatherForecastInfo doInBackground(
  399.                             String... params) {
  400.  
  401.                         return mapUtil.getForecastByCityName(DemoActivity.this, editText.getText().toString(), 2);
  402.                     }
  403.                     @Override
  404.                     protected void onPostExecute(WeatherForecastInfo result) {
  405.  
  406.                         textView.setText(result.getCity().getName()+ " " + result.getCity().getCountry());
  407.                         list = result.getListItem().getWeather(); // Here Im getting NPE why???
  408.                         adapter = new ArrayAdapter<WeatherForecastInfo.ListItem.Weather>(DemoActivity.this, android.R.layout.simple_list_item_1, list);
  409.                         listView.setAdapter(adapter);
  410.                         progressDialog.dismiss();
  411.                     }
  412.                 }.execute(null, null, null);
  413.  
  414.             }
  415.         });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement