B4A Library ICOSWorldForecast 3.50

Laurent95

Active Member
Licensed User
Longtime User
Ciao Giuseppe,

SOLVED: I was calling .CCIcon before any other propery like i.e. .CCWeatherDescription.
Is this a bug?

Hello,
No nothing is related with calling anything other first.
Two possibilities, you call for the data so quick and the time response of website is a bit long, that depends of the bandwith.
In this case, the error aren't returned in library, Android generates an error code who is related with the line of code who is executed at this time.
Or you access to your file without the good command line.
Have you put access to the file in the "Asset" folder first ?
An example below :
LoadBitmapSample(File.DirAssets,"weathericon/wsymbol_0041_clear_intervals_night.png",img2.Width,img2.Height)
 
Last edited:

pantaraf

Member
Licensed User
Longtime User
Thanks Laurent, I've missed to load the icons in the files tab.
I've another question tough...
How can I know if the city I'm looking for does exist, without raising an exception?
Let me explain with an example: I've got an edit where I type the name of the city I'm looking for and a button I push to start data fetching.

1 Sub btnFetch_Click
2 Dim l As List
3 If(edtCity.Text.Length>0) Then
4 Meteo.CityName=edtCity.Text
5 l=Meteo.GetList(edtCity.Text)
6 If(l.Size=1) Then
7 Meteo.CityName=edtCity.Text
8 imgIcon.SetBackgroundImage(Meteo.CCIcon)
9 lblDesc.Text=Meteo.CCWeatherDescription
10 lblTemp.Text=Meteo.CCTempCelsius
11 lblUmidity.Text=Meteo.CCHumidity
12 Else If(l.Size>1) Then
13 'More than 1 city found
14 Else
15 Msgbox("No city by that name.","")
16 End If
17 End If
18 End Sub

On a wrong edtCity.Text (non existent city or typo) I receive an exception at row 4, I've tried to skip row 4 but I always get an error and the app quits at row 5.
Even Giuseppe's demo exits abnormally if the typed text is nonsense.
Does a method exist to find if the requested city is existent or not?

Thank you!
Raffaele
 

Laurent95

Active Member
Licensed User
Longtime User


Hello Raffaele,

You can't know if the city exist, it's why you raise also an error with the demo
You must catch the error. The "Try/Catch/End Try" allows you to catch and manage errors in B4A.
In case you use the "catch" without anything after, put at least the below line code between Catch and End Try.
Log(LastException.Message)

Try this code below, i think that will resolve your problem.

And please use "CODE .../... /CODE" between braquets, when you put code that is most clear in the forum, thank you. I means the both between, i can't show you otherwise the forum take it for code and you don't show my text, sorry, you can use the icon who have inside <> also.

Good programming.
Regards.

B4X:
1 Sub btnFetch_Click
2  Dim l As List
3  If(edtCity.Text.Length>0) Then
4  (new) Try
5                Meteo.CityName=edtCity.Text
6                l=Meteo.GetList(edtCity.Text)
7                If (l.Size=1) Then
X                     ' Meteo.CityName=edtCity.Text -> No, don't do that again.
'For more than one reason, because you send a new request on the website.
'You can have change and the datas can be unaccessible, then, you raise another error.
'You can have an overflow if many people use your program, believe me :=)
8                     imgIcon.SetBackgroundImage(Meteo.CCIcon)
9                     lblDesc.Text=Meteo.CCWeatherDescription
10                    lblTemp.Text=Meteo.CCTempCelsius
11                    lblUmidity.Text=Meteo.CCHumidity
12               Else If(l.Size>1) Then
13                   'More than 1 city found
14               Else
15                   Msgbox("No city by that name.","")
16               End If
17 (new)  Catch
18 (new)      Msgbox("No city found with this name, try another, or maybe correct the spelling.","")
19 (new)  End try
20  End If
21 End Sub
 
Last edited:

pantaraf

Member
Licensed User
Longtime User
Thank you a lot Laurent.
Sorry, I've completely missed the CODE feature.

Ciao.
Raffaele
 

pantaraf

Member
Licensed User
Longtime User
Ciao Giuseppe,
I'm trying to use the FindLocation and AreaName feature to find the actual position of the user.
B4X:
If(Meteo.FindLocation.Length>0) Then
    Try
      Dim city As String
      city= Meteo.FindLocation
      Meteo.CityName=Meteo.AreaName
      edtLoc.Text=Meteo.AreaName
      MeteoUpdate
    Catch
      'Nothing to do :P
    End Try
   End If
The first time I read FindLocation I can read my own location ("Madonna del passo", that's a tiny district in Rieti), worldweather doesn't return an AreaName because, i guess, my own location is too specific to be found. If, then, I use meteo.cityname writing an actual city into the edtLoc edit (let's say I write Rome in it) it does return the correct meteo data. If then I use again the FindLocation feature, I get FindLocation to be "Madonna del Passo" but AreaName still remains on "Rome" returning wrong meteo data. Is this a bug or am I using it in a wrong way?

Grazie.
Raffaele
 

lonleystar

Well-Known Member
Licensed User
Longtime User
2 weeks ago I bought a new computer an Intel Core I7 4470k MB Asus z87-16 GB ram - SSD 128 GB HDD 1 TB everything seemed to work fine, but just SSD and HHD have reported many errors of sectors, have sent them back and I am waiting. For this I´m not in the forum now I am answering with my girlfriend's laptop. but thanks to have reported this error as soon as possible i´ll check it.
 

FreeWolF

Active Member
Licensed User
Longtime User
Yea!! I have a question:

I have wrote that code:

I can't understand how to put ONLY the description of the future weater in a edittext.

For example:

B4X:
Dim a As ICOSWorldForecast    

Activity.LoadLayout("Main")

    a.Initialize("a")   
    a.ApiKey="My API key (free)"
    mCityname = "Rome"
    a.CityName = mCityname

EditText1.Text = a.CCWeatherDescription

With that code I can see the PRESENT weater condition, but if I want to see the condition for tomorrow in an another Edittext, how can I do it?

I repeat: I want only the description, I don't need the Icon

Thanks in advance!!
 

JakeBullet70

Well-Known Member
Licensed User
Longtime User
a.ccxxxxxxxxx = current conditions
a.fcxxxxxxxxx = forcast conditions and is an array

so look at properties that start with fc
 

FreeWolF

Active Member
Licensed User
Longtime User
Thanks a lot to all for the quick reply!!!

I have wrote the following code:

B4X:
Sub Globals
Dim meteo As ICOSWorldForecast
   
   Private EditText1 As EditText
   Private EditText2 As EditText
   Private EditText3 As EditText
   Private EditText4 As EditText
End Sub

Sub Activity_Create(FirstTime As Boolean)

   Activity.LoadLayout("Main")
   
   meteo.Initialize("meteo")
   meteo.CityName = "Carpi"
     
   meteo.ApiKey = "My Weather Key FREE"
   
   EditText1.text = meteo.Short7DayName(0) & " " & meteo.FCDate(0) & " " & meteo.FCWeatherDesc(0)
   EditText2.Text = meteo.Short7DayName(1) & " " & meteo.FCDate(1) & " " & meteo.FCWeatherDesc(1)
   EditText3.Text = meteo.Short7DayName(2) & " " & meteo.FCDate(2) & " " & meteo.FCWeatherDesc(2)
   EditText4.Text = meteo.Short7DayName(3) & " " & meteo.FCDate(3) & " " & meteo.FCWeatherDesc(3)
   
   
End Sub

With that code I receive the following error:

An error has occured in sub: java.lang. NullPointerException: Error Parsing Weather!!! Continue?

Why I receive that error ? Where is the mistake??

I had tried to change the city to another (New York), but the error is always the same......
 

Laurent95

Active Member
Licensed User
Longtime User

Hello,

In first, put your initialisation of the Library with your key before send the city (see the comments in quote).
You catch this error if the Library isn't initialized with an allowed key before that the city was sent.

And after some tip below :

Test if Internet is on.
This Library can return an Error Code who is not totaly related with the context because the latence of the request on Website.
Also put your request in a part of Try/Catch code you can know if your request had results.
The better way before use the results is to make some tests like that :

B4X:
Sub Globals
Dim meteo As ICOSWorldForecast  .../...
    
   meteo.Initialize("meteo")  
   meteo.ApiKey = "My Weather Key FREE"

   If meteo.isWiFiConnected = True Then
        meteo.CityName = "Carpi"

        Try
             Log("now weather AreaName is " & weather.AreaName)
             'Or whatever you want test and you're sure that isn't already filled.
             'This line of print log will return an error if the library cannot return the forecast data.

             EditText1.text = meteo.Short7DayName(0) & "" & meteo.FCDate(0) & "" & meteo.FCWeatherDesc(0)
             EditText2.Text = meteo.Short7DayName(1) & "" & meteo.FCDate(1) & "" & meteo.FCWeatherDesc(1)
             EditText3.Text = meteo.Short7DayName(2) & "" & meteo.FCDate(2) & "" & meteo.FCWeatherDesc(2)
             EditText4.Text = meteo.Short7DayName(3) & "" & meteo.FCDate(3) & "" & meteo.FCWeatherDesc(3)
       Catch
             Log("no weather data returned")
        End Try
    Else
        Log("seems Wifi not work")
    End if
End Sub

Hope that it can help you.

Regards.
 

Laurent95

Active Member
Licensed User
Longtime User
To Giuseppe Salvi, a suggestion.

Hi Giuseppe,

Hope that your computer feels better soon

It will be possible to have the return of an error code if library haven't the weather's datas from Website in a future version ?
I know there are Error codes in return if there are an issue.
Often it's the cause of issues in our developments.

Thanks in advance if it's possible and if that don't take so much of your time, that will be .

Best regards.
Laurent.
 

Laurent95

Active Member
Licensed User
Longtime User

Ciao Raffaele,

I don' t know, if you have found the response but as i'm here
No you don't do any mistake, that's only because the library don't empty the fields before the data are updated i think.
I was had this issue sometime, you must test data before.
Or put them in a database like me that allow you to reset all before.

Emmmmm, maybe be it will be another request at Giuseppe to reset datas before.
Poor guy, Giuseppe hasn't computer for now, and the groceries list grow up (Joke )

Regards.
Laurent.
 

FreeWolF

Active Member
Licensed User
Longtime User


Thanks a lot! Now is working fine!!
 

Laurent95

Active Member
Licensed User
Longtime User
Thanks a lot! Now is working fine!!
You're welcome.

P.S. : A precision, the library of Giuseppe don't returns Error code like i told it before. It's why Android generates an error code who isn't related to the usage of the library, but more to the code's line who is executed. It's why it's sometime difficult to understand the mistake. Anyway, this library stay very good and useful.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…