Android Question [Solved] error at Dim xview As B4XView = xui.CreatePanel("")

Pflichtfeld

Active Member
Licensed User
Using Erels code snippet create round image I get an error in this line:
B4X:
Dim xview As B4XView = xui.CreatePanel("")
where xui -library-link is set and xui is declared as XUI.
Error: (beginning)
Error occurred on line: 27 (clsDrawPics)
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object java.lang.ref.Reference.get()' on a null object reference
at anywheresoftware.b4a.objects.B4XViewWrapper$XUI.CreatePanel(B4XViewWrapper.java:730)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)........

What is wrong here?
 

Pflichtfeld

Active Member
Licensed User
Thanks Klaus!
clsDrawPics is the class, the codeline is in.
Strange: I paused working on that app, shut down the pc. Now where I am back and started everything from scratch, no more error in this line!
Really interesting to experience the surprises of b4a! ;)

Edit: I now found out, how to reproduce this error. Normally I declare my classes just once in Starter as public and initialize them there, because the initialize-routine sometimes takes much time (loading values, calculating stuff...). When I need the class elsewhere, I set a reference to the starter-instance:
In Starter:
B4X:
Sub Service_Create
    clsDraws.Initialize   'is public
    clsGlobVars.Initialize
    ...
in this case, I need the class clsDraws in another class (clsHeader), so there in Initialize I wrote:
B4X:
Public Sub Initialize(PnlBasis As Panel, AName As String)
    draws=Starter.clsDraws   'draws is private in Class_Globals
    Log("Draws is initialized: " & draws.IsInitialized)    'shows true
    'draws.Initialize
when I now call a sub in class clsDraws from clsHeader like:
B4X:
bmp=draws.drawGrindEdge(0,0,gv.LastAngle,0,False,False,True,True,False,False)
the above error occurs within class clsDraws.
If I do not set the class clsDraws as reference in class clsHeader but initialize it there (swap the comments in sub Initialize), this error does not arise.
Is my way of doing it wrong, or is it a bug?
 
Last edited:
Upvote 0
Top