B4A Library ICOSWorldForecast 3.50

lonleystar

Well-Known Member
Licensed User
Longtime User
Hi all, ICOSWorldForecastFree is updated to v3.45 wath's new:

REMOVED

ParseWeatherFromItem

RequestConnectServer

and the unnecessary code and many bugs fixed.

the key is used now once per request not twice like before

please have a lock to the code below how it work.

********************************************​

B4X:
Sub a_LocationResult(Result As String, Value As Boolean)
    If (a.isWiFiConnected) Then
    If (Value) Then       
        If (a.ParseWeather(Result)) Then
            StartActivity(Forecast)
        Else
            toast.Show2("Message:",a.Message)
        End If
    End If
    Else
    toast.Show2("Message:","A data connection is requaired!!")
    End If
End Sub

Sub Activity_Resume

    If Not (a.IsTracking) Then
        a.UpdateLocation
    End If

End Sub

Sub Activity_Pause (UserClosed As Boolean)

    If (UserClosed AND a.IsTracking) Then
        a.RemoveUpdates
    End If

End Sub


Sub b1_Click

    If (a.isWiFiConnected) Then
        If ed0.Text.Length > 0 Then
            If (a.ParseBySearchingCity(ed0.Text)) Then
                If (da.ParseWeather(ed0.Text,"ICOSWorld Forecast Demo v3.40",True)) Then
                    StartActivity(Forecast)
                Else
                    Return
                End If
            Else
                toast.Show2("Message:",a.Message)
            End If
        End If
    End If

End Sub

'************************ Or if U use listview or spinner from designer*******************

Sub b1_click

    l.Clear
    lv1.Clear
    If (a.IsWiFiConnected) Then
        If ed1.Text.Length > 0 Then
            If (a.ParseBySearchingCity(ed1.Text)) Then   --> instead of RequestConnectServer
                l=a.ParseCityList
                For n = 0 To l.Size-1
                    lv1.AddSingleLine(l.get(n))
                Next
            Else
                toast.Show(a.Message)
            End If
        End If
    End If

End Sub

Sub lv1_ItemClick (Position As Int, Value As Object)

    If (a.ParseWeather(Value)) Then
        StartActivity(Forecast)
    Else
        toast.Show2("Message:",a.Message)
    End If
   
End Sub

Below the attached show the message error by using Message.​
 

Attachments

  • noapikey.jpg
    159.3 KB · Views: 176
  • keydisabled.jpg
    160 KB · Views: 196
  • keyerror.jpg
    158.6 KB · Views: 190
  • unabletofindanymatching.jpg
    157.9 KB · Views: 184
Last edited:

Thraka

Member
Licensed User
Longtime User
Hi, have U download the new library? please do and let me know.

I'm having a problem with it. I tried this:
B4X:
If (forecastObject.ParseBySearchingCity("New York")) Then
    Dim desc As String
    desc = forecastObject.CCWeatherDesc     '<----- ERROR
Else

End If

Which doesn't work. The log says:
java.lang.NullPointerException
at it.giuseppe.salvi.library.core.ICOSWorldForecastWrapper.getCCWeatherDesc(ICOSWorldForecastWrapper.java:1176)
 

lonleystar

Well-Known Member
Licensed User
Longtime User

Hi, ParseBySearchingCity only check if the city exist or the provider reports any issue, it doesnt returns the weather's data.

ParseWeather returns the weather's data, look the code below.




B4X:
Sub b1_Click

    If (a.isWiFiConnected) Then
        If ed0.Text.Length > 0 Then
            If (a.ParseBySearchingCity(ed0.Text)) Then
                If (da.ParseWeather(ed0.Text,"ICOSWorld Forecast Demo v3.40",True)) Then
                    StartActivity(Forecast)
                Else
                    Return
                End If
            Else
                toast.Show2("Message:",a.Message)
            End If
        End If
    End If

End Sub

'************************ Or if U use listview or spinner from designer *******************

Sub b1_click

    l.Clear
    lv1.Clear
    If (a.IsWiFiConnected) Then
        If ed1.Text.Length > 0 Then
            If (a.ParseBySearchingCity(ed1.Text)) Then   --> instead of RequestConnectServer
                l=a.ParseCityList
                For n = 0 To l.Size-1
                    lv1.AddSingleLine(l.get(n))
                Next
            Else
                toast.Show(a.Message)
            End If
        End If
    End If

End Sub

Sub lv1_ItemClick (Position As Int, Value As Object)

    If (a.ParseWeather(Value)) Then
        StartActivity(Forecast)
    Else
        toast.Show2("Message:",a.Message)
    End If

End Sub
 

Thraka

Member
Licensed User
Longtime User

I did try that but got the same error. At first I had this:
B4X:
If (forecastObject.ParseBySearchingCity("New York")) Then
    Dim desc As String

    forecastObject.ParseWeather("New York")
    desc = forecastObject.CCWeatherDesc     '<----- ERROR
Else

End If

Additionally, I don't know what this code in your sample does:
B4X:
 If (da.ParseWeather(ed0.Text,"ICOSWorld Forecast Demo v3.40",True)) Then '  <------- Not sure what object da is, ParseWeather only has 1 parameter
 

sdb

Member
Licensed User
Longtime User
I am having the same type of problem when recompiling my program from an earlier version. My api key is correct, it was working previously and I confirmed it with World Weather. I am using B4A 4.0 and ICOSWorldForecast 3.45.

The a.ParseWeather("xxx") returns a true value but when I try to access any data element it fails as above.

I have tried various approaches but no luck.

Also, your da.ParseWeather line in the example has 3 parameters not 1. Not sure I understand how that is working at all.

Thanks,
 

MarcoRome

Expert
Licensed User
Longtime User

strain... if you copy a few code maybe is better to help you :
anyway this code work for me

Bye
 

sdb

Member
Licensed User
Longtime User
Here is the code that is executing. 'Title' is the location passed to the routine. I get the error on the last line.
B4X:
a.Initialize("a")
a.ApiKey="xxxxxxxxxxxxxxxxx"
If a.ParseWeather(Title) = False Then
    Msgbox ("ParseWeather Failure", "Error")
End If
strTest = a.FCTempMinFahrenheit(0)

Here is the error:

** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
Error occurred on line: 170 (main)
java.lang.NullPointerException
at it.giuseppe.salvi.library.core.ICOSWorldForecastWrapper.FCTempMinFahrenheit(ICOSWorldForecastWrapper.java:669)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:636)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:302)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:238)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:121)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:159)
at sb.weathertabs.main.afterFirstLayout(main.java:104)
at sb.weathertabs.main.access$100(main.java:16)
at sb.weathertabs.main$WaitForLayout.run(main.java:76)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4911)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
at dalvik.system.NativeStart.main(Native Method)
** Activity (main) Resume **
 

MarcoRome

Expert
Licensed User
Longtime User
Error in ParseWeather ???

Hi Giuseppe, i have this code that until one week ago work without problem.
Today i have this situation:

B4X:
'If ph.GetDataState <> "CONNECTED" OR myLAN.GetMyIP = "127.0.0.1" Then
If myLAN.GetMyIP = "127.0.0.1" Then
                  ToastMessageShow(lingue.conn_internet, True)      
                ImageView1.Visible = False
                ImageView2.Visible = False
Else
' Testo se la connessione è ok e se restituisce il risultato
Try

        leggimeteo.Initialize("leggimeteo")
        leggimeteo.ApiKey =  "m7sutqf7uxdbr6xxxXXXXXX"
       
  

                    citta = leggimeteo.FindLocation
                    If leggimeteo.ParseWeather(citta) = False Then
                        citta = leggimeteo.LocalIpAddress
                    End If
                    If GetDeviceLayoutValues.ApproximateScreenSize < 5 Then
                            lbmeteo.TextSize = 11
                    End If
                            lbmeteo.Text = leggimeteo.AreaName & " - " & lingue.temperatura_ins & ": C° " & leggimeteo.CCTempCelsius & " (" & leggimeteo.FCTempMinCelsius(0) & "C°|" & leggimeteo.FCTempMaxCelsius(0) & "C°) - " & "F° " & leggimeteo.CCTempFahrenheit & " (" & leggimeteo.FCTempMinFahrenheit(0) & "F°|" & leggimeteo.FCTempMaxFahrenheit(0) & "F°)" & CRLF & _
                            lingue.umidita & leggimeteo.CCHumidity & "% - " &lingue.pressione & leggimeteo.CCPressure
                            lbmeteo.Text = lbmeteo.Text.ToUpperCase




                    lboggi.Text = lingue.meteo_oggi
                    lbdomani.Text = lingue.meteo_domani
      
                    ImageView1.Bitmap = leggimeteo.FCIcon(0)
                    ImageView2.Bitmap = leggimeteo.FCIcon(1)

Catch
'.... Non visualizzo Errore e inserisco non visibili imageview1 e 2
ToastMessageShow(lingue.conn_internet, True)
'ToastMessageShow(leggimeteo.Message, True)

citta = i have "Value right" ( as you can see in this pictures - and so the key work ) but when go in this line

B4X:
If leggimeteo.ParseWeather(citta) = False

i have this error:

B4X:
** Activity (main) Create, isFirst = true **
Error occurred on line: 277 (main)
java.lang.NullPointerException
    at it.giuseppe.salvi.library.core.ICOSWorldForecastWrapper.ParseWeather(ICOSWorldForecastWrapper.java:404)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:636)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:302)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:238)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:121)
    at com.devil.app.night.clock.main.afterFirstLayout(main.java:100)
    at com.devil.app.night.clock.main.access$100(main.java:17)
    at com.devil.app.night.clock.main$WaitForLayout.run(main.java:78)
    at android.os.Handler.handleCallback(Handler.java:733)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:146)
    at android.app.ActivityThread.main(ActivityThread.java:5692)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
    at dalvik.system.NativeStart.main(Native Method)





Change any function in SDK or what.

Any Idea ???

Thank you
Marco
 

lonleystar

Well-Known Member
Licensed User
Longtime User


Ciao Marco, the server change the request url, but I'll change and update the librari sorry for the inconvenient.
 

MarcoRome

Expert
Licensed User
Longtime User
Thank you Giuseppe.
Now this code:
B4X:
citta = leggimeteo.FindLocation
                    If leggimeteo.ParseWeather(citta) = False Then
                        citta = leggimeteo.LocalIpAddress
                    End If
work... but all property CRASH...
example:
B4X:
lbmeteo.Text =  leggimeteo.CCTempCelsius
but also another property have same problem

and this is message:

B4X:
Installing file.
** Activity (main) Pause, UserClosed = false **
PackageAdded: package:com.devil.app.night.clock
** Activity (main) Create, isFirst = true **

java.lang.NullPointerException
    at it.giuseppe.salvi.library.core.ICOSWorldForecastWrapper.getCCTempCelsius(ICOSWorldForecastWrapper.java:1137)
    at com.devil.app.night.clock.main._carica_meteo(main.java:853)
    at com.devil.app.night.clock.main._activity_create(main.java:581)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:187)
    at com.devil.app.night.clock.main.afterFirstLayout(main.java:100)
    at com.devil.app.night.clock.main.access$100(main.java:17)
    at com.devil.app.night.clock.main$WaitForLayout.run(main.java:78)
    at android.os.Handler.handleCallback(Handler.java:733)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:146)
    at android.app.ActivityThread.main(ActivityThread.java:5692)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
    at dalvik.system.NativeStart.main(Native Method)
** Activity (main) Resume **

maybe is change also SDK ?
 

Laurent95

Active Member
Licensed User
Longtime User
Hello Giuseppe,

How i can use the weather by IP now ?
Thanks for say me if it's always possible.

Regards, Laurent.
 

lonleystar

Well-Known Member
Licensed User
Longtime User


Hi marco be patience because WorldWeatherOnline still not work some time yes but the most of the day it still not working.

I get the same error because it doesnt find the date.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…