B4A Library ICOSWorldForecast 3.50

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 , 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

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

Hi Raffaele, can U post or send via e-mail: salvigiuseppe@libero.it the entire code so I can test it too.
 

Laurent95

Active Member
Licensed User
Longtime User

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
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

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.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…