B4J Question Beta 4.2 Error accessing MainForm

stevel05

Expert
Licensed User
Longtime User
This one is driving me nuts!

An app I am using to test the beta has developed a strange issue when it does anything that accesses the main form but only in Debug mode, in release it runs fine.

Layouts load fine to the rootpane, but I am managing the form size, and trying to set it using:

B4X:
MainForm.WindowLeft = ScreenMetrics.GetDefault("left",10.0)
        MainForm.WindowTop = ScreenMetrics.GetDefault("top",10.0)
        MainForm.WindowWidth = ScreenMetrics.GetDefault("width",400.0)
        MainForm.WindowHeight = ScreenMetrics.GetDefault("height",300.0)

Gives me the error:
B4X:
Program started.
(MyMap) {height=639.0, spRightVdiv=0.5, width=816.0, left=432.0, top=124.0, spMainHdiv=0.5}
Error occurred on line: 116 (Main)
java.lang.NullPointerException
    at anywheresoftware.b4j.objects.Form.setWindowLeft(Form.java:152)
    at com.stevel05.snippetmanager.main._applyscreenmetrics(main.java:120)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:606)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:225)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:158)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:90)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:84)
    at com.stevel05.snippetmanager.main.start(main.java:36)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
    at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
    at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
    at java.lang.Thread.run(Thread.java:745)

The map has valid values as you can see from the log.

If I bypass this code, I also get a different error when calling an fx.MsgBox elsewhere in the app:

B4X:
Program started.
Error occurred on line: 774 (Main)
java.lang.NullPointerException
    at anywheresoftware.b4j.objects.Form.getIcon(Form.java:279)
    at anywheresoftware.b4j.objects.JFX.setOwnerAndIcon(JFX.java:124)
    at anywheresoftware.b4j.objects.JFX.Msgbox2(JFX.java:168)
    at com.stevel05.snippetmanager.main._clearsnippet(main.java:720)
    at com.stevel05.snippetmanager.main._btnclearsnippet_action(main.java:756)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:606)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:228)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:158)
    at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:90)
    at anywheresoftware.b4a.BA$2.run(BA.java:165)
    at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
    at java.lang.Thread.run(Thread.java:745)

I did have a custom icon set on the form, which I have removed after seeing this message for the first time but it made no difference.

I have tried:
  • Cleaning the project
  • Closing and reopening the IDE
  • Creating a new project and copying all the modules across.
  • Reinstalling B4j into an empty directory.
  • Moved the Window update to a callsubdelayed from the Appstart sub
The last try gives me this code:
B4X:
    Log(MainForm.Height)
    'At the end of AppStart
    Log(MainForm.Height)                                                       'This call works
    CallSubDelayed(Me,"ApplyScreenMetrics")
    CallSubDelayed(Me,"SetupComplete")
End Sub


Sub ApplyScreenMetrics
'    Log(PackageName)
    If File.Exists(File.DirData(PackageName),"screen.m") Then
        Log(MainForm.Height)                                                    'This one fails
        Log(MainForm.WindowLeft)
        ScreenMetrics = File.ReadMap(File.DirData(PackageName),"screen.m")
        Log(ScreenMetrics)
        MainForm.WindowLeft = ScreenMetrics.GetDefault("left",10.0)
        MainForm.WindowTop = ScreenMetrics.GetDefault("top",10.0)
        MainForm.WindowWidth = ScreenMetrics.GetDefault("width",400.0)
        MainForm.WindowHeight = ScreenMetrics.GetDefault("height",300.0)
        spMain.DividerPositions = Array As Double(ScreenMetrics.GetDefault("spMainHdiv",0.5))
        spRight.DividerPositions = Array As Double(ScreenMetrics.GetDefault("spRightVdiv",0.1))
    Else
        ScreenMetrics.Initialize
    End If
End Sub

Error from the second Log(MainForm.Height)

B4X:
Program started.
600
Error occurred on line: 116 (Main)
java.lang.NullPointerException
    at anywheresoftware.b4j.objects.Form.getHeight(Form.java:234)
    at com.stevel05.snippetmanager.main._applyscreenmetrics(main.java:114)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:606)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:225)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:158)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:90)
    at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:462)
    at anywheresoftware.b4a.keywords.Common.access$0(Common.java:442)
    at anywheresoftware.b4a.keywords.Common$CallSubDelayedHelper.run(Common.java:516)
    at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
    at java.lang.Thread.run(Thread.java:745)

These errors only occur in Debug mode, I am wondering if it may be a memory issue, but that's not what the logs say. The project is a reasonable size, but I wouldn't say it's huge. It does use a few libraries, but not really any more than my usual projects.

I can't easily try putting it into v4 as it is using a Custom View.

I can't get it to fail in a simple project, but I'm out of ideas where to look.
 

stevel05

Expert
Licensed User
Longtime User
Thanks Erel,

I've also included a couple of libraries that you will need and may not have installed.

The easiest way to get it to fail (it won't load the metric file on first run), is to select the bottom right snippet code pane, type anything, then click clear, this will try to open a msgbox.

I am sending to an additional jar file as it's too large to post.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
I've sent you a link to it on my dropbox as GMail wouldn't let me send a jar file :)
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
I just couldn't see it this time. A slip of the Ctrl-V in the wrong place. Many thanks Erel.

That's 5 hours of community support on the forum I owe ;)
 
Upvote 0
Top