Am trying to display a lwuit form when the map is long clicked but I get the following error
java.lang.NullPointerException
at bw.a(), bci=1
at bw.<init>(), bci=6
at bt.<init>(), bci=10
at by.<init>(), bci=48
at bj.a(), bci=10
at fv.<init>(), bci=54
at ex.<init>(), bci=11
at ed.<init>(), bci=33
at com.org.whatsaround.WhatsAroundMidlet.showLocationView(), bci=17
at gm.commandAction(), bci=80
at b.a(), bci=59
at v.b(), bci=10
at c.d(), bci=6
at ez.gestureAction(), bci=237
at com.nokia.mid.ui.gestures.GestureHandler.handleGestureEvent(), bci=60
at com.sun.midp.lcdui.DisplayEventListener.process(), bci=421
at com.sun.midp.events.EventQueue.run(), bci=182
at java.lang.Thread.run(Thread.java:661)
The code is
public void commandAction(Command c, Displayable d) {
if (c == LONG_TOUCH) {
GeoCoordinate coord = longTouch.getTouchAt();
WhatsAroundMidlet.getInstance().showLocationView(country, phoneNumber, firstName, lastName, pTitle, pCategory, backListener, profilePic, coord);
}
}
}
Can be seen from your stack trace, the exception is thrown in your code in the method showLocationView(), the NullPointerException is probably due to one of the parameters in the method call (country, phoneNumber, firstName, lastName,etc.) passing in a object which has not been initialised.
If coord is at fault, you could check this as follows:
if (c == LONG_TOUCH) {
GeoCoordinate coord = longTouch.getTouchAt();
System.out.println(coord);
}
Otherwise you are on your own since you haven't explained how and where in your code country, phoneNumber, firstName, lastName,etc. are actually populated.
Where the names of the functions in the stack trace are un-obfuscated, you can ascertain the following:
com.org.whatsaround.WhatsAroundMidlet.showLocationView() - within this method the exception is thrown.
gm.commandAction() - firing of the Command callback - i.e. entering your own code.
ez.gestureAction() - processing of the gesture within the maps-gesture.jar
com.nokia.mid.ui.gestures.GestureHandler.handleGestureEvent() - This is the Gesture handler created by the maps-gesture.jar which has been invoked due to the long press.
com.sun.midp.lcdui.DisplayEventListener.process() - this is passing events to all registered listeners, in your case this is a LONG PRESS event.
com.sun.midp.events.EventQueue.run() - underlying event loop (from the emulator perhaps?)
Related
I'm working on a blazor server-side project and I have a component that gets passed a model (pickedWeek) as a parameter. I can use the model fine in-line with the html, but OnInitializedAsync always thinks that the model is null.
I have passed native types in as parameters, from the Page into a component, this way without an issue. I use a NullWeek as a default parameter, so the number getting used in OnInitializedAsync only ever appears to be from the NullWeek. In case this is related, there is a sibling component that is returning the Week model to the Page through an .InvokeAsync call, where StateHasChanged() is being called after the update. It appears that the new Week is getting updated on the problem component, but that OnInitializeAsync() either doesn't see it, or just never fires again- which maybe is my problem, but I didn't think it worked that way.
For instance, the below code will always show "FAILURE" but it will show the correct Week.Number. Code below:
<div>#pickedWeek.Number</div>
#if(dataFromService != null)
{
<div>SUCCESS</div>
}
else
{
<div>FAILURE</div>
}
#code{
[Parameter]
public Week pickedWeek { get; set; }
protected IEnumerable<AnotherModel> dataFromService { get; set; }
protected override async Task OnInitializedAsync()
{
if (pickedWeek.Number > 0)
{
dataFromService = await _injectedService.MakeACall(pickedWeek.Id);
}
}
}
#robsta has this correct in the comments, you can use OnParametersSet for this. Then, you will run into another issue, in that each rerender will set your parameters again and generate another call to your service. I've gotten around this by using a flag field along with the the OnParametersSet method. Give this a shot and report back.
private bool firstRender = true;
protected override async Task OnParametersSetAsync()
{
if (pickedWeek.Number > 0 && firstRender)
{
dataFromService = await _injectedService.MakeACall(pickedWeek.Id);
firstRender = false;
// MAYBE call this if it doesn't work without
StateHasChanged();
}
}
Another alternative is to use the OnAfterRender override, which supplies a firstRender bool in the the method signature, and you can do similar logic. I tend to prefer the first way though, as this second way allows it to render, THEN sets the value of your list, THEN causes another rerender, which seems like more chatter than is needed to me. However if your task is long running, use this second version and build up a loading message to display while the list is null, and another to display if the service call fails. "FAILURE" is a bit misleading as you have it as it's being displayed before the call completes.
I've also found that a call to await Task.Delay(1); placed before your service call can be useful in that it breaks the UI thread loose from the service call awaiter and allows your app to render in a loading state until the data comes back.
Prerequisites:
xmlns:p="http://primefaces.org/ui"
javax.faces.component.UIComponent
Setup:
org.primefaces:primefaces:jar:6.1.2
org.glassfish:javax.faces:jar:2.2.14
Tomcat 8.5.28
Proprietary OR Mapper
#Property
private Calendar cal;
public Calendar getCal() {
return ORMapper.getProperty(this, "cal");
}
Functional setup:
p:commandButton that during its action executes code (that leads to the error) and then opens a dialogue which contains
<p:calendar id="cal" value="#{bean.model.cal}" />
Execution:
During Invoke Application of the commandButton (action) we traverse a section of the DOM tree that does NOT contain the dialogue (i.e. that dialogue is not a child of component) using
component.visitTree(
VisitContext.createVisitContext(
FacesContext.getCurrentInstance(),
null,
Collections.singleton(VisitHint.SKIP_UNRENDERED)),
(context, component) -> {
...
return VisitResult.ACCEPT;
}
);
Before the tree execution
model.cal = value
model.getCal() = value
Errorneous behaviour:
After the tree execution
model.cal = null
model.getCal() = value
This then leads to an error when validating the model which has a violation on e.g. #NotNull on the property (not the getter)
Notes:
Using IntelliJ attempts where made to find the change: Field Access/Modification breakpoints, calls to get/setter breakpoints, EL Method Invoker breakpoints
Removing the visitTree call fixes the Problem
Removing the element from the dialogue fixes the problem
Later on the value is set again, when couldnt be figured out either
i have two jsf pages (home.jsf and employees.jsf) ,
home page has a button that navigates to employees page,
while navigating i store value in session scope
at (Managed bean)
public void putSessionAL(ActionEvent actionEvent) {
FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("key","value");
}
public String navigate() {
return "employees";
}
i want to change Label at employees viewObject from UIHints tab depending on value stored at session using the following groovy expression
adf.context.sessionScope.key
and changed trustMode to trusted but it fires the following exception
oracle.jbo.script.ExprScriptException: JBO-29114 ADFContext is not setup to process messages for this exception. Use the exception stack trace and error code to investigate the root cause of this exception. Root cause error code is JBO-25188. Error message parameters are {0=Employees.FirstName, 1=, 2=oracle.jbo.script.ExprSecurityException}
at oracle.jbo.script.ExprScriptException.throwException(ExprScriptException.java:316)
at oracle.jbo.script.ExprScriptException.throwExceptionWithExprDef(ExprScriptException.java:387)
at oracle.jbo.ExprEval.processScriptException(ExprEval.java:599)
at oracle.jbo.ExprEval.doEvaluate(ExprEval.java:697)
at oracle.jbo.ExprEval.evaluate(ExprEval.java:508)
at oracle.jbo.ExprEval.evaluate(ExprEval.java:487)
at oracle.jbo.common.NamedObjectImpl.resolvePropertyRaw(NamedObjectImpl.java:680)
at oracle.jbo.server.DefObject.resolvePropertyRaw(DefObject.java:366)
One way to do it at the VO UIHint attribute label level will be programmaticaly by doing as follow :
In your VO go to the java tab and add the RowImpl java class
In the VORowImpl Add the following function
public String getMySessionLabel() {
return (String)FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("key");
}
In the Label add the following EL expression :
adf.object.getMySessionLabel()
This technique allow you more control than pure EL, if you want to do more than getting from session for example. In your case pure EL, as you did, should work as well. (Would need to check what is wrong with yours, maybe just missing the
#{adf.context.sessionScope.key}
If you attempt to get your label from a method in viewRowImpl. So this will be executed at least once for each row. I think this solution isn't fit for your case.
anyway ADF as a framework added strong policy and validations in EL in general and especially in version 12.2.x.
The solution for you case as following:
Create new class in model layer which extends oracle.jbo.script.ExprSecurityPolicy class
Override checkProperty method.
#Override
public boolean checkProperty(Object object, String string, Boolean b) {
if (object.getClass().getName().equals("oracle.adf.share.http.ServletADFContext") && string.equals("sessionScope")) {
return true;
}
return super.checkProperty(object, string, b);
}
Open adf-config.xml source and in startup tag set your class ExprSecurityPolicy property.
like:
<startup ExprSecurityPolicy="model.CustomExprSecurityPolicy">
I just received an exception when I try to reference a static variable in another class, which is also statically initialized. This worked before, and for some reason it fails now. The only changes I made were resetting Visual Studio (2010) to its default setting, which I can't imagine to be the reason for this. Any other code I added didn't touch any of the affected parts either.
This is my code
WinForms class 'MainForm':
partial class MainForm : Form
{
// ...
private RefClass convMan;
private Dictionary<EnumType, string> LogNames = RefClass.LogNames;
// ...
public MainForm() { .... }
}
Referenced class 'RefClass':
class RefClass
{
// ...
public enum EnumType { TypeOne = 0, TypeTwo = 1, TypeThree = 2 };
public static Dictionary<EnumType, string> LogNames = new Dictionary<EnumType, string>()
{
{ EnumType.TypeOne, "Text0" },
{ EnumType.TypeTwo, "Text1" },
{ EnumTypy.TypeThree, "Text2" }
};
}
The error I get now is (translated from German):
An unhandled exception of type "System.TypeInitializationException" occurred.
Additional information: The type initializer for "RefClass" threw an exception.
which has the InnerException
System.ArgumentException
So, as far as I'm concerned, my static dictionary should be initialized once it gets accessed, thus when my Form class references it. I tried debugging to see if the static dictionary is initialized before it gets referenced in the Form class, which is not the case. Also, when I stop at a breakpoint for the reference line, the variable LogNames is null.
I'm really confused as to why this happens, it all worked before.
I found my error, the exceptions I got were quite misleading though. It was a problem with a different dictionary than the one I referenced. It probably didn't get initialized in the first place because something before that failed (If someone can clear this up, please feel free to do so!). Basically what I did wrong was using a two-directional dictionary and adding a value twice. This should normally produce a normal exception, but since it was done statically it got wrapped into a TypeInitializationException. I had a deeper look into the exact stacktrace of the inner exception and found where the exception originated from. Maybe this helps someone in the future...
I had a simular issue getting the same exception. Found that my static constructor for my utility class was generating the exception. Took some time locating since the description of the exception was misleading.
As #Yeehaw mentioned, it appears that the exception gets wrapped, so the common denominator here I would say is that the class/object is static.
I want to test using mockito, that some events are triggered when a javafx ObservableList is modified.
I have tried to to it this way :
#Test
public void handleListChanged() throws Exception {
// [given]
ObservableList<String> list = FXCollections.observableArrayList();
ListChangeListener<String> listener = mock(ListChangeListener.class);
list.addListener(listener);
// [when]
list.add("test");
// [then]
ArgumentCaptor<Change> argument = ArgumentCaptor.forClass(Change.class);
verify(listener).onChanged(argument.capture());
assertTrue(argument.getValue().wasAdded());
}
bu an IllegalStateException raises on the last line :
java.lang.IllegalStateException
at com.sun.javafx.collections.NonIterableChange.checkState(NonIterableChange.java:101)
at com.sun.javafx.collections.NonIterableChange.getPermutation(NonIterableChange.java:81)
at javafx.collections.ListChangeListener$Change.wasPermutated(ListChangeListener.java:156)
at javafx.collections.ListChangeListener$Change.wasAdded(ListChangeListener.java:165)
at FXCollectionsTest.handleListChanged(FXCollectionsTest.java:28
The documentation of the wasAdded() method warns that an IllegalArgumentException could be thrown "if this Change is in initial state" but i don't understand it.
Why my code is not working ?
Is there a solution for testing this code using mockito ?
You must call the next method first on the Change object before you can call any other method like wasAdded.
Unit test
assertTrue(argument.getValue().next());
assertTrue(argument.getValue().wasAdded());
Documentation
public abstract boolean next()
Go to the next change. In initial state is invalid a require a call to next() before calling other methods. The first next() call will make this object represent the first change.
Source