Android Question use WeatherView with JavaObject

mzsoft

Member
hi.
i want to use this library.
i write this code and work fine.
B4X:
#AdditionalJar: kotlin-stdlib-1.3.21
#AdditionalJar: WeatherView-3.0.0.aar
#AdditionalJar: confetti-1.1.1.aar

B4X:
Dim ctxt As JavaObject
    ctxt.InitializeContext
    weatherview.InitializeNewInstance("com.github.matteobattilana.weather.WeatherView", Array(ctxt, Null))
    
    weatherview.RunMethod("setScaleFactor", Array(1.0F))
    weatherview.RunMethod("setAngle", Array(0))
    weatherview.RunMethod("setSpeed", Array(100))
    'weatherview.RunMethod("setFadeOutPercent", Array(1.0F))
    weatherview.RunMethod("setEmissionRate", Array(10.0F))
weatherview.RunMethod("setPrecipType", Array("SNOW"))

    Activity.AddView(weatherview, 0, 0, 100%x, 100%y)

    weatherview.RunMethod("resetWeather", Null)

but now i need to set weather to Rain.

B4X:
weatherview.RunMethod("setPrecipType", Array("RAIN"))

but this error show

B4X:
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create (first time) **
** Activity (main) Resume **
java.lang.NoSuchFieldError: No instance field currentVelocityX of type F in class Lcom/github/matteobattilana/weather/confetti/MotionBlurBitmapConfetto; or its superclasses (declaration of 'com.github.matteobattilana.weather.confetti.MotionBlurBitmapConfetto' appears in /data/app/b4a.example.ra-1/base.apk)
    at com.github.matteobattilana.weather.confetti.MotionBlurBitmapConfetto.drawInternal(WeatherConfettoGenerator.kt:39)
    at com.github.jinatonic.confetti.confetto.Confetto.draw(Confetto.java:342)
    at com.github.jinatonic.confetti.confetto.Confetto.draw(Confetto.java:332)
    at com.github.jinatonic.confetti.ConfettiView.onDraw(ConfettiView.java:132)
    at android.view.View.draw(View.java:15231)
    at android.view.View.updateDisplayListIfDirty(View.java:14167)
    at android.view.View.getDisplayList(View.java:14189)
    at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3410)
    at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3389)
    at android.view.View.updateDisplayListIfDirty(View.java:14127)
    at android.view.View.getDisplayList(View.java:14189)
    at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3410)
    at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3389)
    at android.view.View.updateDisplayListIfDirty(View.java:14127)
    at android.view.View.getDisplayList(View.java:14189)
    at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3410)
    at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3389)
    at android.view.View.updateDisplayListIfDirty(View.java:14127)
    at android.view.View.getDisplayList(View.java:14189)
    at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3410)
    at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3389)
    at android.view.View.updateDisplayListIfDirty(View.java:14127)
    at android.view.View.getDisplayList(View.java:14189)
    at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3410)
    at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3389)
    at android.view.View.updateDisplayListIfDirty(View.java:14127)
    at android.view.View.getDisplayList(View.java:14189)
    at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:273)
    at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:279)
    at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:318)
    at android.view.ViewRootImpl.draw(ViewRootImpl.java:2530)
    at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2352)
    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1982)
    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1061)
    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5885)
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
    at android.view.Choreographer.doCallbacks(Choreographer.java:580)
    at android.view.Choreographer.doFrame(Choreographer.java:550)
    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:135)
    at android.app.ActivityThread.main(ActivityThread.java:5254)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)


I could not fix it.Can anyone help?
 

drgottjr

Expert
Licensed User
Longtime User
i think this will be a problem. the weatherview library uses yet another library: confetti

here is where the exception occurs:
B4X:
                PrecipType.RAIN -> {
                    var rainStretch = RAIN_STRETCH * (confettoInfo.scaleFactor + 1.0f) / 2f;
                    val dX = currentVelocityX                     // <------------------------------------
                    val dY = currentVelocityY


as the exception indicates, there is no currentVelocityX field in the confetti
generator class for rain (there is no currentVelocityY field either). there are
velocityX and velocityY fields, which are settable, but it's not clear that these fields
are the same as the currentVelocityX and currentVelocityY fields.

under normal circumstances, it might be possible to use reflection to assign values to
existing fields, but reflection can't create fields for a class.

i could find no indication where currentVelocityX and currentVelocityY are defined. i looked
in both the weatherview and confetti libraries. frankly, i don't understand how the
weatherview library could even be built as those 2 fields don't exist (apparently). i guess
that's one of the benefits of kotlin: make it up as you go along.

assuming that currentvelocityX and currentVelocityY are the same as velocityX and velocityY,
the weatherview library could be rebuilt after changing those references.

the weatherview library is 4 years old, confetti is even older. since the non-existent fields
occur in weatherview's code, i think maybe its author is the only one who can clarify how those variables
can be set or where they are actually declared. send him an email: matbat96@gmail.com.
refer to lines 5 and 6 above where the exception is thrown.
 
Last edited:
Upvote 0
Top