Hello, I have a problem with a method that is executed on solution start:
The start method calls another method that will add some scheduler jobs. At this point, I get an exception:
org.mozilla.javascript.JavaScriptException: java.lang.NullPointerExceptionorg.mozilla.javascript.JavaScriptException: java.lang.NullPointerException
at org.mozilla.javascript.JavaScriptException.wrapException(JavaScriptException.java:69)
at org.mozilla.javascript.FunctionObject.call(FunctionObject.java:457)
at org.mozilla.javascript.ScriptRuntime.call(ScriptRuntime.java:1237)
at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:1940)
at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:94)
at com.servoy.j2db.scripting.e.call(Unknown Source)
at org.mozilla.javascript.ScriptRuntime.call(ScriptRuntime.java:1237)
at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:1940)
at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:94)
at com.servoy.j2db.scripting.e.call(Unknown Source)
at com.servoy.j2db.develop.debugger.n.a(Unknown Source)
at com.servoy.j2db.develop.debugger.n.executeFunction(Unknown Source)
at com.servoy.j2db.FormManager.if(Unknown Source)
at com.servoy.j2db.develop.ab.if(Unknown Source)
at com.servoy.j2db.FormManager$3.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
This exception will never occur when executing the startup method right after startup or any time later.
Any ideas what the problem is or what I can do about it?
how does the script look like?
the main startup method populates some globals etc. At the end, a method is called that
- gets a user id from the security (current user)
- executes a SQL statement
- triggers the found records using the scheduler
This is where I have my problem…
what do you exactly do with " triggers the found records using the scheduler "
could you post the script?
In a startup script you shouldn’t go to forms or foundsets!
what I do is this:
var user = security.getUserId();
var heute = new Date();
var start = heute.getFullYear() + '-' + (heute.getMonth() + 1) + '-' + heute.getDate() +
' ' + heute.getHours() + ':' + heute.getMinutes() + ':' + heute.getSeconds()
var ende = heute.getFullYear() + '-' + (heute.getMonth() + 1) + '-' + heute.getDate() +
' 23:59:59'
var maxReturedRows = 100; // maximal 100 Wiedervorlagen werden gelesen
var dataset;
var wvl_ids = new Array();
var wvl_datum = new Array();
var query = 'select uid_wiedervorlage, wiedervorlage_am from wiedervorlagen where ' +
'uid_benutzer = ' + user + ' AND ' +
'wiedervorlage_am >= \'' + start + '\' AND ' +
'wiedervorlage_am <= \'' + ende + '\' AND ' +
'status <> 1 order by wiedervorlage_am'
dataset = databaseManager.getDataSetByQuery(controller.getServerName(), query, null, maxReturedRows);
if (dataset.getMaxRowIndex() > 0)
{
wvl_ids = dataset.getColumnAsArray(1);
wvl_datum = dataset.getColumnAsArray(2);
for ( var i = 0 ; i < wvl_ids.length ; i++ )
{
triggerWiedervorlage(wvl_ids[i], wvl_datum[i]);
}
}
I probably should add some more info:
This method is not global, it resides in a form. The method calls another method “triggerWiedervorlage()” on the same form, that will schedule a job with a given ID and a given date.
The problem seems to be related to your statement
In a startup script you shouldn’t go to forms or foundsets!
Why is this and what exactly does it mean. In my case I am not really “going to that form” and I am not using a foundset either, rather a dataset.
ok this method i see here is already the second script (which resides in a form) ?
Very difficult to see at the moment where it goes wrong. If i look at youre stacktrace i see that it happens in the second script (so it seems that triggerWiedervorlage is not yet called)
I have to know how for it exactly goes.
Is the query fired? Do you have the dataset?
If you start with java.exe (not javaw.exe)
and you use application.output(“XXX”) on places in youre script you should be able to see how for it goes.
For example it can be that: controller.getServerName triggers a null..
Tip: about the script you posted:
var query = 'select uid_wiedervorlage, wiedervorlage_am from wiedervorlagen where uid_benutzer = ? AND wiedervorlage_am >= ? AND wiedervorlage_am <= ? AND status <> 1 order by wiedervorlage_am'
dataset = databaseManager.getDataSetByQuery(controller.getServerName(), query, new Array(user,start,ende), maxReturedRows);
Then you leave formatting (tricky date formatting) to database driver
To Johan:
I have added several “return;” to narrow down where I “crash”. Now I found it: that method “triggerWiedervorlage” is called and the exit point is right here
plugins.scheduler.getCurrentJobNames();
This is where I get the error. To make sure: That only happens on Solution start. If you call that right after the startup method has run, there is no problem.
To Jan:
That is a very interesting syntax. I always wondered about that object parameter. So if I get you right: all question marks are substituted by their corresponding position in the Array, that I can pass (first ?: Array[0], second ?: Array[1]…). And a date will be handled in what way?
Thanks to both!
patrick:
So if I get you right: all question marks are substituted by their corresponding position in the Array, that I can pass (first ?: Array[0], second ?: Array[1]…). And a date will be handled in what way?
correct, you/servoy sent the objects to the database driver which does the correct formatting required by the database.
very strange
i made a global method:
forms.valuelistsEntry.testStart();
and that one is callign a form method:
var x = controller.getServerName();
application.output(x);
var p = plugins.scheduler.getCurrentJobNames()
application.output(p);
and i don’t get an error.
So there has to be something else that also triggers this.
Do you have a reproduceable test case?
very strange, here too!
I created a sample solution, based on the same tables. No luck, everything works fine.
Now I went back to my original solution and put application.output at almost all steps. Everytime I start up it exists at a different step up to a point where it doesn’t complain at all (twice I started now without error)!?
I am confused!
The most “common” point where I get an error seems to be a point, where in that table wiedervorlagen a record gets saved. This is not even part of the method I posted before, but a method that is executed earlier:
if (dataset.getMaxRowIndex() > 0)
{
controller.loadRecords(dataset);
for ( var i = 1 ; i <= controller.getMaxRecordIndex() ; i++ )
{
var record = foundset.getRecord(i);
if (!record.urspruenglicher_termin)
{
record.urspruenglicher_termin = record.wiedervorlage_am;
}
datum_neu = new Date();
datum_neu = new Date(datum_neu - 1000 + 1000 + (1000*60*offset));
record.wiedervorlage_am = datum_neu;
application.output('this point is reached')
controller.saveData();
application.output('this point is not reached')
}
}
But as I said before, it is not always this point?!?
Is that piece off method executed before the startupmethod piecies you showed before?
But it comes down to things that you really shoudn’t touch foundset/saves ect in youre startupscript. This should be done in the onload or onshow (with the first time boolean) of a form
onStartup is more for setting some security things for example in globals ect.
Because in a onStartupScript the solution (read forms) aren’t really there yet. It is a really early stage in loading the solution.
and wouldn’t it be better to execute the startup method after all the loading has been done?
In my case I see no workaround. This whole thing is about reminders. At startup I want to
- transfer all open todos to today (I think this is where we have that problem)
- trigger a method for all open todos
I need data for this and I need to do this at login time. The only workaround I see is to trigger something that is executed 5 seconds after login or so… A trigger that triggers the triggers…
You could trigger the code at onShow of your first form (the form as specified in the solution settings)
we can’t call the open solution method later because that would trigger it after show first form.
But if you can’t do it in the onShow of the first form We need to have an example soluion when you get that nullpointer. To see if we can make it better so that you can do more things in the onSolutionStartup then you should do now.
I wasn’t able to create a reproducable test case. I can send you “the big thing”, but that will create some 90+ tables…
that doesn’t matter you can send it over if you want. Please include sample data because i don’t think youre method will do much without it.