How do I debug errors like this in Codenameone? - codenameone

I have an app that works well on the simulator. I did an Android build and installed on a device. Now , several functionalities don't work. The debug log I receive contain several errors of this sort
[EDT] 0:23:31,275 - Exception in Ziemozi version 1.0
[EDT] 0:23:31,275 - OS and
[EDT] 0:23:31,275 - Error java.lang.NullPointerException: Attempt to invoke virtual method 'void com.codename1.ab.l.n(int)' on a null object reference
[EDT] 0:23:31,276 - Current Form null
[EDT] 0:23:31,276 - Exception: java.lang.NullPointerException - Attempt to invoke virtual method 'void com.codename1.ab.l.n(int)' on a null object reference
java.lang.NullPointerException: Attempt to invoke virtual method 'void com.codename1.ab.l.n(int)' on a null object reference
at com.codename1.g.j.a(InfiniteScrollAdapter.java:156)
at com.codename1.g.j.a(InfiniteScrollAdapter.java:143)
at com.codename1.ab.aa.t(InfiniteContainer.java:177)
at com.codename1.ab.aa$5.run(InfiniteContainer.java:193)
at com.codename1.ab.r.n(Display.java:1298)
at com.codename1.ab.r.l(Display.java:1242)
at com.codename1.ab.r.k(Display.java:1130)
at com.codename1.ab.ao.run(RunnableWrapper.java:120)
at com.codename1.impl.b$1.run(CodenameOneThread.java:60)
How do I debug this or how does it arise so I can fix it?

This happens when one of the components returned from InfiniteContainer is null. E.g. you did something like:
public Component[] fetchComponents(int index, int amount);
// ...
return cmps;
}
cmps is a valid array that's bigger than 0 but one of its elements is null.

Related

Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: Cannot read property 'defaultView' of undefined [duplicate]

I am trying to use Selenium for Python eith the Chrome webdriver to automate the download of a file.
My program works perfectly up to the last step (clicking on the 'download' button) at which point a dialog box is triggered with the text:
"An error has occured in 'site url': Uncaught TypeError: Cannot read property 'getColomnSet' of undefined41"
What does this error mean and what are the most probable causes?
For reference, here are the last few commands of my program:
try:
elem = wait.until(EC.presence_of_element_located((By.ID,'element_1_id')))
finally:
elem1 = driver.find_element_by_id('element_1_id')
elem2 = driver.find_element_by_id('element_2_id')
action = ActionChains(driver).move_to_element(elem1).move_to_element(elem2)
action.perform()
elem2.click()
This error message...
An error has occured in 'site url': Uncaught TypeError: Cannot read property 'getColomnSet' of undefined
...implies that your program was unable to read the property getColomnSet while trying to download the desired file.
Possibly, the main problem is the js involved to download the document is invoked before the client renders the HTML DOM completely.
The relevant HTML, a bit more of your previous lines of code and the error stack trace would have given us some more idea about what's going wrong.
Solution
You can induce some measures to wait till the complete DOM Tree is rendered following the discussion:
Generic funtion to check if page has completely loaded in Selenium
A couple of facts:
In your code trials I don't see you interacting with the element (By.ID,'element_1_id') so possibly you can remove the step of presence_of_element_located() for the element (By.ID,'element_1_id').
If you still require presence_of_element_located((By.ID,'element_1_id')) catch the exception and initiate required steps.
As you invoke move_to_element() over elem1 and elem2 and moving ahead invoke perform() you need to induce WebDriverWait with expected_conditions as element_to_be_clickable(locator)
tl;dr (references)
Cannot read property 'getContext' of null, using canvas
Uncaught TypeError: Cannot read property 'getContext' of undefined
Uncaught Error remote.js
Try the following - it works on Salesforce Lightning UI screens:
WebElement element = driver.findElement(By.id("your ID"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", element);

Codename One - Play a sound

The following code works fine in the Simulator, I hear the audio:
try {
Media m = MediaManager.createMedia((Display.getInstance().getResourceAsStream(getClass(), "/notification_sound_bell.mp3")), "audio/mpeg");
m.play();
} catch (IOException err) {
Log.e(err);
}
But it doesn't work at all on real Android devices. What's wrong?
On the generated apk, the "notification_sound_bell.mp3" file is placed in /res/raw folder.
On an Android 4.x device I get:
[EDT] 0:0:0,118 - Codename One revisions: 3b20edadec808867afc2b19774268b66890616ad
[EDT] 0:0:0,129 - Exception: java.lang.NullPointerException - null
java.lang.NullPointerException at
com.codename1.impl.android.AndroidImplementation.createMedia(AndroidImplementation.java:2802)
at com.codename1.ui.Display.createMedia(Display.java:2998) at
com.codename1.media.MediaManager.createMedia(MediaManager.java:125)
at com.codename1.media.MediaManager.createMedia(MediaManager.java:94)
at
it.galgani.app.fiveMinutesAlert.MyApplication.start(MyApplication.java:66)
at
it.galgani.app.fiveMinutesAlert.MyApplicationStub.run(MyApplicationStub.java:140)
at com.codename1.ui.Display.processSerialCalls(Display.java:1116) at
com.codename1.ui.Display.mainEDTLoop(Display.java:911) at
com.codename1.ui.RunnableWrapper.run(RunnableWrapper.java:120) at
com.codename1.impl.CodenameOneThread$1.run(CodenameOneThread.java:60)
at java.lang.Thread.run(Thread.java:856) [EDT] 0:0:0,214 - Exception
in Alert every five minutes version 1.0 [EDT] 0:0:0,215 - OS and [EDT]
0:0:0,215 - Error java.lang.NullPointerException [EDT] 0:0:0,216 -
Current Form null [EDT] 0:0:0,217 - Exception:
java.lang.NullPointerException - null java.lang.NullPointerException
at
com.codename1.impl.android.AndroidImplementation.createMedia(AndroidImplementation.java:2802)
at com.codename1.ui.Display.createMedia(Display.java:2998) at
com.codename1.media.MediaManager.createMedia(MediaManager.java:125)
at com.codename1.media.MediaManager.createMedia(MediaManager.java:94)
at
it.galgani.app.fiveMinutesAlert.MyApplication.start(MyApplication.java:66)
at
it.galgani.app.fiveMinutesAlert.MyApplicationStub.run(MyApplicationStub.java:140)
at com.codename1.ui.Display.processSerialCalls(Display.java:1116) at
com.codename1.ui.Display.mainEDTLoop(Display.java:911) at
com.codename1.ui.RunnableWrapper.run(RunnableWrapper.java:120) at
com.codename1.impl.CodenameOneThread$1.run(CodenameOneThread.java:60)
at java.lang.Thread.run(Thread.java:856)
On an Android 7.x device I get:
[EDT] 0:0:20,186 - Codename One revisions:
3b20edadec808867afc2b19774268b66890616ad
[EDT] 0:0:20,191 - Exception: java.lang.NullPointerException - Attempt
to invoke virtual method 'int java.io.InputStream.read(byte[], int,
int)' on a null object reference java.lang.NullPointerException:
Attempt to invoke virtual method 'int java.io.InputStream.read(byte[],
int, int)' on a null object reference at
com.codename1.impl.android.AndroidImplementation.createMedia(AndroidImplementation.java:2802)
at com.codename1.ui.Display.createMedia(Display.java:2998) at
com.codename1.media.MediaManager.createMedia(MediaManager.java:125)
at com.codename1.media.MediaManager.createMedia(MediaManager.java:94)
at
it.galgani.app.fiveMinutesAlert.MyApplication.start(MyApplication.java:66)
at
it.galgani.app.fiveMinutesAlert.MyApplicationStub.run(MyApplicationStub.java:140)
at com.codename1.ui.Display.processSerialCalls(Display.java:1116) at
com.codename1.ui.Display.mainEDTLoop(Display.java:911) at
com.codename1.ui.RunnableWrapper.run(RunnableWrapper.java:120) at
com.codename1.impl.CodenameOneThread$1.run(CodenameOneThread.java:60)
at java.lang.Thread.run(Thread.java:762) [EDT] 0:0:20,198 - Exception
in Alert every five minutes version 1.0 [EDT] 0:0:20,199 - OS and
[EDT] 0:0:20,201 - Error java.lang.NullPointerException: Attempt to
invoke virtual method 'int java.io.InputStream.read(byte[], int, int)'
on a null object reference [EDT] 0:0:20,202 - Current Form null [EDT]
0:0:20,204 - Exception: java.lang.NullPointerException - Attempt to
invoke virtual method 'int java.io.InputStream.read(byte[], int, int)'
on a null object reference java.lang.NullPointerException: Attempt to
invoke virtual method 'int java.io.InputStream.read(byte[], int, int)'
on a null object reference at
com.codename1.impl.android.AndroidImplementation.createMedia(AndroidImplementation.java:2802)
at com.codename1.ui.Display.createMedia(Display.java:2998) at
com.codename1.media.MediaManager.createMedia(MediaManager.java:125)
at com.codename1.media.MediaManager.createMedia(MediaManager.java:94)
at
it.galgani.app.fiveMinutesAlert.MyApplication.start(MyApplication.java:66)
at
it.galgani.app.fiveMinutesAlert.MyApplicationStub.run(MyApplicationStub.java:140)
at com.codename1.ui.Display.processSerialCalls(Display.java:1116) at
com.codename1.ui.Display.mainEDTLoop(Display.java:911) at
com.codename1.ui.RunnableWrapper.run(RunnableWrapper.java:120) at
com.codename1.impl.CodenameOneThread$1.run(CodenameOneThread.java:60)
at java.lang.Thread.run(Thread.java:762)
It seems our system has a special treatment to the notification_sound prefix in a file name on Android for usage with background notification sounds on Android. Just rename the file to something else and it should work as expected.

Random issues with ViewEngine in Nancy 2.0.0 pre-release

I've been experiencing some odd issues with my application that I am not sure how to go about tracking down because it is so random. I was wondering if there may be any ideas based on the stack trace below.
Here is some quick bullet points:
Issue seems to be related to code in the View (.cshtml)
It RANDOMLY appears and it has something to do with the session cookie because if you try from another computer then it is no issue or if you clear your cache it is no issue
My GetUserByIdentifier is wrapped in a try{}catch{} which returns NULL if we enter the catch{}.. which should redirect to the login screen.
Could this be something internal causing the error message? This unhandled exception can even happen on my login.cshtml page which doesn't even have any code in the view.
The error message:
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index]
System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource) +72
System.SZArrayHelper.get_Item(Int32 index) +13816967
Nancy.ViewEngines.Razor.RazorViewEngine.GetLineNumber(Int32 startLineIndex, IReadOnlyList`1 compilationSource) +39
Nancy.ViewEngines.Razor.<>c__DisplayClass19_0.<BuildErrorMessages>b__0(Diagnostic error) +118
System.Linq.WhereSelectArrayIterator`2.MoveNext() +80
System.Linq.WhereEnumerableIterator`1.MoveNext() +51
System.Linq.Buffer`1..ctor(IEnumerable`1 source) +250
System.Linq.Enumerable.ToArray(IEnumerable`1 source) +106
Nancy.ViewEngines.Razor.RazorViewEngine.BuildErrorMessages(IEnumerable`1 errors, IList`1 templateLines, IReadOnlyList`1 compilationSource) +272
Nancy.ViewEngines.Razor.RazorViewEngine.BuildErrorMessage(EmitResult result, ViewLocationResult viewLocationResult, String sourceCode) +366
Nancy.ViewEngines.Razor.<>c__DisplayClass14_0.<GenerateRazorViewFactory>b__0() +49
Nancy.ViewEngines.Razor.RazorViewEngine.GetViewInstance(ViewLocationResult viewLocationResult, IRenderContext renderContext, Object model) +1064
Nancy.ViewEngines.Razor.<>c__DisplayClass9_0.<RenderView>b__0(Stream stream) +4700
Nancy.Hosting.Aspnet.<ProcessRequest>d__2.MoveNext() +381
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +13891908
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +61
System.Web.TaskAsyncHelper.EndTask(IAsyncResult ar) +69
System.Web.CallHandlerExecutionStep.OnAsyncHandlerCompletion(IAsyncResult ar) +178

NullPointer on Bitmap.getWidth in Codenameone Android app

I have an app created in CodenameOne running on Android that is throwing NullPinterExpections after trying to scale too many images. I've used CacheMap to help the situation but still get the issue after loading too many images.
Here is my code that throws the issue, from within InfiniteContainer fetchComponents
Image i = (Image) MoveService.getInstance().getImage(thumbnail_url);
if (i == null) {
i = theme.getImage(move.getThumbnail_url());
if (i != null) {
i = i.fill(width+20, (width / 2) * 3);
MoveService.getInstance().putImage(move.getThumbnail_url(), i);
}
}
And here is what I get from the logs:
[EDT] 0:8:57,596 - Exception: java.lang.NullPointerException - Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference
java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference
at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:748)
at com.codename1.impl.android.c.a(AndroidImplementation.java:1688)
at com.codename1.k.s.c(Image.java:1008)
at com.codename1.k.s.c_(Image.java:954)
at com.codename1.k.s.b(Image.java:919)
at com.codename1.impl.android.c$8.a(AndroidImplementation.java:6216)
at com.codename1.k.n.a(EncodedImage.java:627)
at com.codename1.k.n.b(EncodedImage.java:654)
at com.codename1.k.s.e(Image.java:903)
at com.codename1.k.s.f(Image.java:974)
at com.altitude.studios.polebible.e$b.<init>(Unknown Source)
at com.altitude.studios.polebible.e$16.a(Unknown Source)
at com.codename1.k.u.m(InfiniteContainer.java:143)
at com.codename1.k.u$5.run(InfiniteContainer.java:172)
at com.codename1.k.m.l(Display.java:1154)
at com.codename1.k.m.j(Display.java:1098)
at com.codename1.k.m.i(Display.java:999)
at com.codename1.k.ad.run(RunnableWrapper.java:120)
at com.codename1.impl.b$1.run(CodenameOneThread.java:60)
at java.lang.Thread.run(Thread.java:818)
This can happen if an image went thru the wrong pipeline and the underlying native image is gone. If the image is a font image or a similar "exotic" image try converting it to a regular image using toEncodedImage() or similar method.
It can also happen if you explicitly invoked dispose() on an image.

How to use ReactiveUI with WinForms

I have decided to learn ReactiveUI after seeing what can be done with it, but my enthusiasm has been broken at the first attempt to run a simple project. I have recreated the example from this article, using reactiveui-winforms.Net40 version 6.5.0 from NuGet. Everything compiles ok, but i get an exception during runtime at the following line
var OKCmdObs = this.WhenAny(vm => vm.EnteredText,
s => !string.IsNullOrWhiteSpace(s.Value));
System.InvalidOperationException occurred
HResult=-2146233079
Message=The current thread has no Dispatcher associated with it.
Source=System.Reactive.Windows.Threading
StackTrace:
at System.Reactive.Concurrency.DispatcherScheduler.get_Current()
at ReactiveUI.PlatformRegistrations.<>c.<Register>b__0_7() in C:\workspace\git-perso\ReactiveUI\ReactiveUI\Platform\Registrations.cs:line 75
InnerException:
Does anyone have any idea of what's happening ?
The mentioned article does not have the compiled project available for download, and i didn't find any complete "Hello-World" project for reactiveui-winforms.
My test project can be downloaded here.
In Visual Studio, if i Continue(F5), another exception occures :
System.NullReferenceException occurred
HResult=-2147467261
Message=Object reference not set to an instance of an object.
Source=ReactiveUI
StackTrace:
at ReactiveUI.IROObservableForProperty.<>c__DisplayClass1_0.<GetNotificationForProperty>b__6(IReactivePropertyChangedEventArgs`1 x) in C:\workspace\git-perso\ReactiveUI\ReactiveUI\IROObservableForProperty.cs:line 44
InnerException:
If i continue to hit F5 i get :
System.Exception was unhandled by user code
HResult=-2146233088
Message=An OnError occurred on an object (usually ObservableAsPropertyHelper) that would break a binding or command. To prevent this, Subscribe to the ThrownExceptions property of your objects
Source=ReactiveUI
This exception is caused because RxUI always tries to initialize for WPF, even though (because you're also using the winforms package) it'll override this setting with a Winforms-based scheduler right after.
It should be harmless though, as it's catched and ignored. You're probably hitting it within VS ?

Resources