NullPointer on Bitmap.getWidth in Codenameone Android app - codenameone

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.

Related

Katalon : Unable to click on object after use switchTo and waitForElementClickable

I have problem with find element in my script. I use switchToframe and waitForElementClickable and a still have error
Unable to click on object 'Object Repository/1_2.Wniosek_o_OsFiz_v2/Page_Do wysyki i robocze - seap-testskgpl/label_Zaznacz lini' (Root cause: com.kms.katalon.core.exception.StepFailedException: Unable to click on object 'Object Repository/1_2.Wniosek_o_OsFiz_v2/Page_Do wysyki i robocze - seap-testskgpl/label_Zaznacz lini'
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.stepFailed(WebUIKeywordMain.groovy:64)
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:26)
at com.kms.katalon.core.webui.keyword.builtin.ClickKeyword.click(ClickKeyword.groovy:76)
at com.kms.katalon.core.webui.keyword.builtin.ClickKeyword.execute(ClickKeyword.groovy:43)
at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:72)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.click(WebUiBuiltInKeywords.groovy:616)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$click$1.call(Unknown Source)
at 1_2.Wniosek_o_OsFiz_v2.run(1_2.Wniosek_o_OsFiz_v2:85)
at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:337)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:328)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:307)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:299)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:233)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:114)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:105)
at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
at TempTestCase1586510087999.run(TempTestCase1586510087999.groovy:23)
This is details for my element:
And this is my code (I still work in iframe, page reload. Element is in this same iframe):
WebUI.waitForElementClickable(findTestObject('Object Repository/1_2.Wniosek_o_OsFiz_v2/Page_Do wysyki i robocze - seap-testskgpl/label_Zaznacz lini'),
10)
WebUI.click(findTestObject('Object Repository/1_2.Wniosek_o_OsFiz_v2/Page_Do wysyki i robocze - seap-testskgpl/label_Zaznacz lini'))
Somebody can help me ?
The XPath for the link you are trying to get is generated by web-recorder. Those selectors tend to be flaky because they are dynamic (so, they won't be the same every time you run the tests). I suggest you learn how to get the XPath yourself using Google DevTools or similar.
In this particular case, change the value of Selected Locator from //div[#id='document0']/div[3]/label to //a[#title='Documenty do wysylki'].

How do I debug errors like this in 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.

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);

Can not find Image path in Upload document script using Sikuli with webdriver

Can not find Image path in Upload document script using Sikuli with selenium web driver, I am using latest Sikuli jar. I am getting following Error while running followed code snippet:
Screen src = new Screen();
Match addFile= src.find("C:\\Users\\Inknopwledge\\Desktop\\TestSikuli\\Capture.PNG");
FindFailed: can not find C:\Users\Inknopwledge\Desktop\Sikuli\Capture.PNG on the screen.
Line ?, in File ?
at org.sikuli.script.Region.handleFindFailed(Region.java:420)
at org.sikuli.script.Region.wait(Region.java:511)
at org.sikuli.script.Region.find(Region.java:381)
at pagefactory.profile_section.ResearchandExp_pageFact.click_Attach_Documents(ResearchandExp_pageFact.java:195)
at TestCase.ResearchandExpertise_TC.attach_Document_to_Research(ResearchandExpertise_TC.java:311)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
at org.testng.TestRunner.privateRun(TestRunner.java:767)
at org.testng.TestRunner.run(TestRunner.java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
at org.testng.TestNG.run(TestNG.java:1057)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
Unable to upload document [Ljava.lang.StackTraceElement;#17c395e
"As per your statement Exception is : FindFailed: can not find C:\Users\Inknopwledge\Desktop\Sikuli\Capture.PNG on the screen.
This exception occurs when image with given path not found on screen within 3 second (default auto wait timeout for find operation in sikuli is 3 seconds) with default simillarity 0.7
You can make wait to load image then use find command or use:
Screen s = new Screen();
Pattern p = new Pattern ("img path/path").similar( (float) 0.7);
if (s.exists(p , 7) != null) {
Match match = s.getLastMatch();
}
Above command wait for 7 sec for image to appear on screen. Change your similarity percentage to get match. you image may be different form that displayed on app.
I had the same issue when using this in conjunction with Appium Driver. I realized that the image that I was snipping using my mac was not the one Sikuli could find. There are two resolutions then:
Download and install Sikuli IDE and use that for the snaps
Use the following code:
import org.sikuli.script.FindFailed;
import org.sikuli.script.Screen;
public void capture (String path){
Screen screen = new Screen();
screen.userCapture().save(path);
}
This would basically freeze the screen and allow you to snip the image and store it in the path which you mention. You can use an IDE to run this or create an executable jar file to run it from command line

GWT RequestFactory occasionally Illegal Argument Exception

I'm giving the first steps with the GWT Request Factory and I'm having an occasionally exception. What I find strange is that it doesn't happen in every server request...just sometimes.
The exception is:
> Caused by: java.lang.IllegalArgumentException: Something other than a Java object was returned from JSNI method
> '#com.google.web.bindery.autobean.gwt.client.impl.JsniCreatorMap::invoke(Lcom/google/gwt/core/client/JavaScriptObject;Ljava/lang/Object;Ljava/lang/Object;)':
> JS value of type boolean, expected java.lang.Object
I get an error when I call:
> Request<List<ConcertProxy>> findAll();
Which is implemented like this:
public static List<Concert> findAll()
{
Objectify ofy = ObjectifyService.begin();
List<Concert> concerts = ofy.query(Concert.class).limit(100).order("-id").list();/* this dumps to memory */
return concerts;
}
Nothing to do with RequestFactory, this is a Chrome DevMode Plugin bug. Google recommends using Firefox (or IE) for DevMode: http://code.google.com/p/google-web-toolkit/issues/detail?id=5778#c65

Resources