B4A Library ICOSWorldForecast 3.50

View attachment 14755 View attachment 14754 View attachment 16846 Hi guys, ICOSWorldForecast is here.


It's a pleasure to introduce the new library of weather forecast.

The zip include:

The library, and the demo

INSTALLATION:

Copy the Library in your Basic For Android Library.

Copy the folder weathericon is located in files in the demo. In your one.


RENAME:
ICOSWorldForecast2.71.part1.zip and ICOSWorldForecast2.71.part2.zip

TO:
ICOSWorldForecast2.71.part1.rar and ICOSWorldForecast2.71.part1.rar

In this version I add WeatherUrl and 2 more days forecast.

You can use your own icons, instead of my icons.

For this new version 2.71 you need the new key.

You must register to obtain the new key, otherwise you will get error.

Use the address below to register.

World Weather Online - Welcome to the World Weather Online Developer Network!

don't forget to replace the ApiKey="XXXXXXXXXXXXXX" with your private key

This demos, I made with my galaxy tab 7 600x1024

any question or bugs please report to me.

big Thx to warwound for is fantastic auto-generated reference.


ICOSWorldForecast
Author:
Giuseppe Salvi
Version: 2.81
  • ICOSWorldForecast
    Methods:
    • FCDate (index As Int) As String
      Return Date for which the weather is forecasted
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.FCDate(0)
    • FCIcon (index As Int) As Bitmap
      Return Weather symbol image
      example:
      Dim a As ICOSWorldForecast
      Image1.SetBackgroundImage=a.FCWeatherIcon(0)
    • FCIconUrl (index As Int) As String
      Return URLIcon For Forecast Condition
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.FCIconUrl(0)
    • FCPrecipitationMM (index As Int) As String
      Return Precipitation amount in millimeter
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.FCPrecipitationMM(0)
    • FCTempMaxCelsius (index As Int) As String
      Return Day and night max temperature in Celcius
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.FCTempMaxCelsius(0)
    • FCTempMaxFahrenheit (index As Int) As String
      Return Day and night max temperature in Fahrenheit
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.FCTempMaxFahrenheit(0)
    • FCTempMinCelsius (index As Int) As String
      Return Day and night min temperature in Celcius
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.FCTempMinCelsius(0)
    • FCTempMinFahrenheit (index As Int) As String
      Return Day and night max temperature in Fahrenheit
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.FCTempMinFahrenheit(0)
    • FCWeatherCode (index As Int) As String
      Return Weather Code
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.FCWeatherCode(0)
    • FCWeatherDesc (index As Int) As String
      Return Weather description
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.FCWeatherDesc(0)
    • FCWinddir16Point (index As Int) As String
      Return 16-Point compass wind direction
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.FCWinddir16Point(0)
    • FCWinddirDegree (index As Int) As String
      Return Wind direction in degree
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.FCWinddirDegree(0)
    • FCWinddirection (index As Int) As String
      Return Compass Wind direction
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.FCWinddirection(0)
    • FCWindspeedKmph (index As Int) As String
      Return Wind speed in kilometer per hour
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.FCWindspeedKmph(0)
    • FCWindspeedMiles (index As Int) As String
      Return Wind speed in Miles per hour
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.FCWindspeedMiles(0)
    • FindLatAndLong As String
      Retrieve accurate latitude and longitude from GPS or network services
    • FindLocation As String
      Retrieve accurate location from GPS or network services
    • Full7DayName (day As Int) As String
      Return Full name of the day ( Monday )
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.Full7DayName(0) ' 0 = today - 1 = tomorrow etc etc
    • GetList (mCity As String) As ArrayList
      Set the City Name you wish to get the weather
      example:
      Dim a As ICOSWorldForecast
      Dim l As List
      Dim lv1 As ListView
      l = a.GetList("Los Angeles")
      For n = 0 To l.Size-1
      lv1.AddSingleLine(l.Get(n))
      Next
      Sub lv1_ItemClick (Position As Int, Value As Object)ics.CityName = lv1.GetItem(Position)
      lv1.Clear
      End Sub
    • Initialize (EventName As String)
      Initilize the object
    • Short7DayName (day As Int) As String
      Return Short name of the day ( Mon )
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.Short7DayName(0) ' 0 = today - 1 = tomorrow etc etc
    • StringFormat (format As String, object As Object, object1 As Object) As String
      Return Formatted String
      example:
      Label1.Text=StringFormat("Lat: %1$s - Long: %2$s ",Latitude,Longitude)
    • isWiFiConnected As Boolean
      Check if WiFi is Connected
    Permissions:
    • android.permission.ACCESS_ASSISTED_GPS
    • android.permission.ACCESS_COARSE_LOCATION
    • android.permission.ACCESS_FINE_LOCATION
    • android.permission.ACCESS_GPS
    • android.permission.ACCESS_LOCATION_EXTRA_COMMANDS
    • android.permission.ACCESS_NETWORK_STATE
    • android.permission.ACCESS_WIFI_STATE
    • android.permission.CONTROL_LOCATION_UPDATES
    • android.permission.INTERNET
    Properties:
    • ApiKey As String [write only]
      Set your personal ApiKey
      example:
      Dim a As ICOSWorldForecast
      a.ApiKey="XXXXXXXXXXXXXXXXXXXXXXXXXXXX"
    • AreaName As String [read only]
      Return Name of the city
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.AreaName
    • CCCloudCover As String [read only]
      Return Cloud Cover in %
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.CCCloudCover
    • CCHumidity As String [read only]
      Return Humidity in %
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.CCHumidity
    • CCIcon As Bitmap [read only]
      Return Weather symbol image
      example:
      Dim a As ICOSWorldForecast
      Image1.SetBackgroundImage=a.CCWeatherIcon
    • CCIconUrl As String [read only]
      Return URLIcon For Current Condition
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.CCIconUrl
    • CCLocalObsDateTime As String [read only]
      Return Local Observation date and time
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.CCLocalObsDateTime
    • CCObservationTime As String [read only]
      Return Observation time (UTC)
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.CCObservationTime
    • CCPrecipitationMM As String [read only]
      Return Precipitation Amount in Millimeter
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.PrecipitationMM
    • CCPressure As String [read only]
      Return Atmospheric pressure in Milibars
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.CCPressure
    • CCTempCelsius As String [read only]
      Return Temperature in Celsius
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.CCTempCelsius
    • CCTempFahrenheit As String [read only]
      Return Temperature in Fahrenheit
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.CCTempFahrenheit
    • CCVisibility As String [read only]
      Return Visibility kilometers per hour
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.CCVisibility
    • CCWeatherCode As String [read only]
      Return Weather Code
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.CCWeatherCode
    • CCWeatherDescription As String [read only]
      Return Weather Description
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.CCWeatherDescription
    • CCWinddir16Point As String [read only]
      Return 16-Point wind direction compass
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.CCWinddir16Point
    • CCWinddirDegree As String [read only]
      Return Wind direction in degree
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.CCWinddirDegree
    • CCWindspeedKmph As String [read only]
      Return Wind speed in kilometer per hour
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.CCWindspeedKmph
    • CCWindspeedMiles As String [read only]
      Return Wind speed in Miles per hour
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.CCWindspeedMiles
    • CityName As String [write only]
      Set City you wish to get the weather
      example:
      Dim a As ICOSWorldForecast
      a.CityName="New York"
    • Country As String [read only]
      Return Name of the Country
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.Country
    • CurrentDate As String [read only]
      Return Current Day,Month,Year ( Friday, 28 September, 2012 )
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.CurrentDate
    • CurrentTime As String [read only]
      Return Current time ( 02.09 PM )
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.CurrentTime
    • DstOffset As String [read only]
      Return DstOffset = ( GMT +2 )
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.DstOffset
    • GmtOffset As String [read only]
      Return GmtOffset = ( GMT +1 )
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.GmtOffset
    • LatAndLong As String [write only]
      Set Lat and Long you wish to get the weather
      example:
      Dim a As ICOSWorldForecast
      a.LatAndLong="40.714,-74.006"
    • Latitude As Object [read only]
      Return Latitude of the city
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.Latitude
    • Longitude As Object [read only]
      Return Longitude of the city
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.Longitude
    • Population As String [read only]
      Return Population of the city
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.Population
    • Region As String [read only]
      Return Name of the Region
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.Region
    • Sunrise As String [read only]
      Return Sunrise = 06:04
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.Sunrise
    • Sunset As String [read only]
      Return Sunset = 19:36
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.Sunset
    • TimeZoneID As String [read only]
      Return TimeZoneID = Europe/Rome
      example:
      Dim a As ICOSWorldForecast
      Label1.Text=a.TimeZoneID
    • Version As Double [read only]
      Return the version of this library
    • WeatherUrl As String [read only]
      Return url of the city [ http://www.worldweatheronline.com/London-weather/City-of-London-Greater-London/GB.aspx ]
      example:
      Dim Webview1 As Webview
      Webview1.LoadUrl(a.WeatherUrl)
 

Attachments

  • ICOSWorldForecast_DEMO.part1.zip
    293 KB · Views: 887
  • ICOSWorldForecast_DEMO.part2.zip
    167.1 KB · Views: 703
  • Main.png
    Main.png
    86.8 KB · Views: 852
  • Widget.jpg
    Widget.jpg
    81.8 KB · Views: 842
  • ICOSWorldForecast.png
    ICOSWorldForecast.png
    156.3 KB · Views: 906
  • ICOSWorldForecastFree_v3.50_lib_fix.zip
    53.9 KB · Views: 451
Last edited:

Laurent95

Active Member
Licensed User
Longtime User
Hi Giuseppe,
In tests i have see a "_done" variable in the debug window of B4A, in future can we have something like that for test if all data are updated ?
Or maybe that isn't related with the update ?
Also something who will be useful, it's we can read the City, for now it's write only, maybe it's possible to put it read and write ?
It still have some problems to update the data around 11pm UTC time, they seems very busy on server each day.
That's why i try to find a way for report the update when it's so long.

Thank you for your responses.

Regards, Laurent.
 

lonleystar

Well-Known Member
Licensed User
Longtime User
Hi Giuseppe,
In tests i have see a "_done" variable in the debug window of B4A, in future can we have something like that for test if all data are updated ?
Or maybe that isn't related with the update ?
Also something who will be useful, it's we can read the City, for now it's write only, maybe it's possible to put it read and write ?
It still have some problems to update the data around 11pm UTC time, they seems very busy on server each day.
That's why i try to find a way for report the update when it's so long.

Thank you for your responses.

Regards, Laurent.
Hi , to get the response for update I'll try, but I know the provider update every 3 hours, for the city I get it from areaname.
 

microbox

Active Member
Licensed User
Longtime User
@lonleystar Sorry to bother you again, I tried your code but it is giving me this message "There is a problem parsing the package" :(..any idea what is it?
 

pantaraf

Member
Licensed User
Longtime User
Ciao Giuseppe,
I'm using your library after a while, the last version that I've used was the 2.81. I've downloaded the 3.30. Beside a couple of changed method names everything seemed to work fine. But when I try to download the forecasts then I can only read the (0)th, the (1)st doesn't return a forecast. My api key subscription is the free one, on the world weather online developer website I saw that the free subscription allows to have 5 days forecasts. In your opinion, is this only a transitory problem from world weather online?

Grazie.
Raffaele
 

lonleystar

Well-Known Member
Licensed User
Longtime User
Ciao Giuseppe,
I'm using your library after a while, the last version that I've used was the 2.81. I've downloaded the 3.30. Beside a couple of changed method names everything seemed to work fine. But when I try to download the forecasts then I can only read the (0)th, the (1)st doesn't return a forecast. My api key subscription is the free one, on the world weather online developer website I saw that the free subscription allows to have 5 days forecasts. In your opinion, is this only a transitory problem from world weather online?

Grazie.
Raffaele

Hi Raffaele, sorry I was in Italy and I arrived a few hours ago.

can U post an example please, because to me work fine.

Ciao Raffaele, sono stato in Italia e sono arrivato qualche ora fa.

Mi puoi postare un esempio, perche a me funziona benissimo.


P.S.

Till tomorrow I'll Upload the new update.
 

pantaraf

Member
Licensed User
Longtime User
Ciao Giuseppe,
my code is the following, right before switching to 3.30 the app worked flawlessly, I could choose the city and get 5 days forecasts. After switching to 3.30 only the first forecast day can be retrieved:
B4X:
Dim wc As Int
	For i=-1 To 4
		If (i=-1) Then
	    	  wc=Meteo.CCWeatherCode		 
	   	Else	    	
		 	lblTmp(i+1).Text="T "&Meteo.FCTempMinCelsius(i)&"/"&Meteo.FCTempMaxCelsius(i)&"°C"
	     	        lblprec(i+1).Text="Precipitazioni: "&Meteo.FCPrecipitationMM(i)&" mm"	   
			viewMeteo(i+1).Gravity=Gravity.FILL
	     	        wc=Meteo.FCWeatherCode(i)
                       viewMeteo(i+1).SetBackgroundImage(LoadBitmapSample(File.DirAssets,Meteo.FCIconUrl(i).SubString(Meteo.CCIconUrl.IndexOf("wsymbol_")),viewMeteo(i+1).Width,viewMeteo(i+1).Height))	     
	   	End If
I'm in a try catch section and i can see only the ccweathercode and fcweathercode(0) retrieved and showed. fcweathercode(1) returns null values.

Grazie.
Raffaele
 

lonleystar

Well-Known Member
Licensed User
Longtime User
Ciao Giuseppe,
my code is the following, right before switching to 3.30 the app worked flawlessly, I could choose the city and get 5 days forecasts. After switching to 3.30 only the first forecast day can be retrieved:
B4X:
Dim wc As Int
    For i=-1 To 4
        If (i=-1) Then
              wc=Meteo.CCWeatherCode       
           Else          
             lblTmp(i+1).Text="T "&Meteo.FCTempMinCelsius(i)&"/"&Meteo.FCTempMaxCelsius(i)&"°C"
                     lblprec(i+1).Text="Precipitazioni: "&Meteo.FCPrecipitationMM(i)&" mm"     
            viewMeteo(i+1).Gravity=Gravity.FILL
                     wc=Meteo.FCWeatherCode(i)
                       viewMeteo(i+1).SetBackgroundImage(LoadBitmapSample(File.DirAssets,Meteo.FCIconUrl(i).SubString(Meteo.CCIconUrl.IndexOf("wsymbol_")),viewMeteo(i+1).Width,viewMeteo(i+1).Height))       
           End If
I'm in a try catch section and i can see only the ccweathercode and fcweathercode(0) retrieved and showed. fcweathercode(1) returns null values.

Grazie.
Raffaele

Hi Raffaele, can U post or send via e-mail: [email protected] the entire code so I can test it too.
 

Laurent95

Active Member
Licensed User
Longtime User
Ciao Giuseppe,
my code is the following, right before switching to 3.30 the app worked flawlessly, I could choose the city and get 5 days forecasts. After switching to 3.30 only the first forecast day can be retrieved:
B4X:
Dim wc As Int
    For i=-1 To 4
        If (i=-1) Then
              wc=Meteo.CCWeatherCode        
           Else           
             lblTmp(i+1).Text="T "&Meteo.FCTempMinCelsius(i)&"/"&Meteo.FCTempMaxCelsius(i)&"°C"
                     lblprec(i+1).Text="Precipitazioni: "&Meteo.FCPrecipitationMM(i)&" mm"      
            viewMeteo(i+1).Gravity=Gravity.FILL
                     wc=Meteo.FCWeatherCode(i)
                       viewMeteo(i+1).SetBackgroundImage(LoadBitmapSample(File.DirAssets,Meteo.FCIconUrl(i).SubString(Meteo.CCIconUrl.IndexOf("wsymbol_")),viewMeteo(i+1).Width,viewMeteo(i+1).Height))        
           End If
I'm in a try catch section and i can see only the ccweathercode and fcweathercode(0) retrieved and showed. fcweathercode(1) returns null values.

Grazie.
Raffaele

Ciao Raffaele,

Maybe it's a bit late to reply, but i was far away of B4A since a while.
I have the same issue when i get the new 3.x version, have you initialized the number of days forecasted at the begin of activity ?
B4X:
a.Initialize("a")
a.NumOfDays=5
By default in library the number of days to forecast is 1.

Regards, Laurent.
 

JakeBullet70

Well-Known Member
Licensed User
Longtime User
Hi lonelystar
Just ran into this one. Here is the line that cause it:

SunriseTime = forecastObject.Sunrise

================================================
*** Extended Error thrown ***
java.lang.StringIndexOutOfBoundsException: length=0; regionStart=10; regionLength=6
java.lang.String.startEndAndLength(String.java:583)
java.lang.String.substring(String.java:1468)
it.giuseppe.salvi.library.core.ICOSWorldForecastWrapper.getSunrise(ICOSWorldForecastWrapper.java:941)
com.sadLogic.KitchenCentral.clsweatherdata._update_weather(clsweatherdata.java:529)
com.sadLogic.KitchenCentral.clsweatherdata._update_weather_default_city(clsweatherdata.java:644)
com.sadLogic.KitchenCentral.clsweatherdata._tryupdate(clsweatherdata.java:280)
com.sadLogic.KitchenCentral.clsweatherdata._internet_onconnected(clsweatherdata.java:181)
java.lang.reflect.Method.invokeNative(Native Method)
java.lang.reflect.Method.invoke(Method.java:525)
anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:853)
anywheresoftware.b4a.keywords.Common.CallSubNew(Common.java:802)
com.sadLogic.KitchenCentral.clsevent._raise(clsevent.java:104)
com.sadLogic.KitchenCentral.svrcheckweb._jobdone(svrcheckweb.java:195)
java.lang.reflect.Method.invokeNative(Native Method)
java.lang.reflect.Method.invoke(Method.java:525)
anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
anywheresoftware.b4a.keywords.Common$5.run(Common.java:952)
android.os.Handler.handleCallback(Handler.java:800)
android.os.Handler.dispatchMessage(Handler.java:100)
android.os.Looper.loop(Looper.java:194)
android.app.ActivityThread.main(ActivityThread.java:5370)
java.lang.reflect.Method.invokeNative(Native Method)
java.lang.reflect.Method.invoke(Method.java:525)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
dalvik.system.NativeStart.main(Native Method)
================================================


I am using V3.30
Thanks
 

Thraka

Member
Licensed User
Longtime User
When I pass a bad city name in, it seems to crash my program. For example:

B4X:
If (forecastObject.RequestConnectServer("test2", True)) Then
    forecastObject.ParseWeather
Else
    Dim Ex As ExceptionEx
    Ex.Initialize("Unable to connect to weather server")
    Ex.Throw
End If

This exception is seen in the B4A log:
B4X:
java.lang.RuntimeException: An error occured while executing doInBackground()

 at android.os.AsyncTask$3.done(AsyncTask.java:299)
 at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
 at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
 at java.util.concurrent.FutureTask.run(FutureTask.java:239)
 at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
 at java.lang.Thread.run(Thread.java:856)
Caused by: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
 at android.os.Handler.<init>(Handler.java:197)
 at android.os.Handler.<init>(Handler.java:111)
 at android.widget.Toast$TN.<init>(Toast.java:324)
 at android.widget.Toast.<init>(Toast.java:91)
 at android.widget.Toast.makeText(Toast.java:238)
 at it.giuseppe.salvi.library.core.provider.ICOSForecastWrapper$ICOSBackgroundWorkGetWeaterAsync.doInBackground(ICOSForecastWrapper.java:78)
 at it.giuseppe.salvi.library.core.provider.ICOSForecastWrapper$ICOSBackgroundWorkGetWeaterAsync.doInBackground(ICOSForecastWrapper.java:1)
 at android.os.AsyncTask$2.call(AsyncTask.java:287)
 at java.util.concurrent.FutureTask.run(FutureTask.java:234)
 ... 4 more

Is there a way to test if a city is valid?
 

lonleystar

Well-Known Member
Licensed User
Longtime User
When I pass a bad city name in, it seems to crash my program. For example:

B4X:
If (forecastObject.RequestConnectServer("test2", True)) Then
    forecastObject.ParseWeather
Else
    Dim Ex As ExceptionEx
    Ex.Initialize("Unable to connect to weather server")
    Ex.Throw
End If

This exception is seen in the B4A log:
B4X:
java.lang.RuntimeException: An error occured while executing doInBackground()

at android.os.AsyncTask$3.done(AsyncTask.java:299)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
at java.util.concurrent.FutureTask.run(FutureTask.java:239)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
at java.lang.Thread.run(Thread.java:856)
Caused by: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
at android.os.Handler.<init>(Handler.java:197)
at android.os.Handler.<init>(Handler.java:111)
at android.widget.Toast$TN.<init>(Toast.java:324)
at android.widget.Toast.<init>(Toast.java:91)
at android.widget.Toast.makeText(Toast.java:238)
at it.giuseppe.salvi.library.core.provider.ICOSForecastWrapper$ICOSBackgroundWorkGetWeaterAsync.doInBackground(ICOSForecastWrapper.java:78)
at it.giuseppe.salvi.library.core.provider.ICOSForecastWrapper$ICOSBackgroundWorkGetWeaterAsync.doInBackground(ICOSForecastWrapper.java:1)
at android.os.AsyncTask$2.call(AsyncTask.java:287)
at java.util.concurrent.FutureTask.run(FutureTask.java:234)
... 4 more

Is there a way to test if a city is valid?
Hi, ofcours U get error, U cant parse test2 as a city U must give a valid city.
 

Thraka

Member
Licensed User
Longtime User
The problem is that it crashes the program, even in Try Catch it crashes my program. I have a window that lets a person type in the city they want to check for, I don't always know that they will put something good in there.
 

gadgetmonster

Active Member
Licensed User
Longtime User
The problem is that it crashes the program, even in Try Catch it crashes my program. I have a window that lets a person type in the city they want to check for, I don't always know that they will put something good in there.

Hi Thraka,

One way around this (all be it a bit long winded) is to use the GeoCoder library. This allows a search of a city and definitely does not crash when given an invalid entry. On a successfully search you can then pass the city name or coordinates over to the weather library.
 

Thraka

Member
Licensed User
Longtime User
Hi Thraka,

One way around this (all be it a bit long winded) is to use the GeoCoder library. This allows a search of a city and definitely does not crash when given an invalid entry. On a successfully search you can then pass the city name or coordinates over to the weather library.

Thank you for the tip. I guess I'll have to take the long way around :(
 

Thraka

Member
Licensed User
Longtime User
@lonleystar

Can you make the library multithreaded? It pauses my app for a good second every time I update the weather. I used to have my update code in another thread but with your latest version it crashes saying "Can't create handler inside thread that has not called Looper.prepare()

Considering your library is going out to a web service, which for whatever reason *could* be delayed, you should really have this automatically in another thread that calls back an event like Control_WeatherUpdate or something.
 

Thraka

Member
Licensed User
Longtime User
@lonleystar

I keep getting this toast alert on some devices: error: no gps or network provider is enabled

This happens after I call Initialize. How can I turn that off?
 

Thraka

Member
Licensed User
Longtime User
Thank you for the tip. I guess I'll have to take the long way around :(

This didn't really work. One some devices the call to that extra geolocation library just never returns. It's not 100% reliable. However, no matter the workaround, this library shouldn't have a crash. Something is happening somewhere deep that causes the try catch to not catch the exception correctly.
 
Top