I'm running a simple CodenameOne app where an image is downloaded and displayed in the form.
'
int WIDTH = Display.getInstance().getDisplayWidth();
Form f = new Form();
f.getToolbar().hideToolbar();
f.getStyle().setBgColor(0xFFFFFF);
EncodedImage placeholder = EncodedImage.createFromImage(Image.createImage(WIDTH, WIDTH), false);
URLImage puppyImage = URLImage.createToStorage(placeholder, "puppy.png", "https://images.newscientist.com/wp-content/uploads/2021/06/03141753/03-june_puppies.jpg?crop=1:1,smart&width=1200&height=1200&upscale=true");
Container imageContainer = new Container();
imageContainer.add(puppyImage);
f.add(imageContainer);
f.show();
'
I'm not sure what I'm doing incorrectly (or did incorrectly), while I used a proxy everything ran fine, and the image is downloaded and saved. Now if I run the app without the proxy I get the following error and stack trace:
'
java.net.ConnectException: Connection refused: connect
at java.base/java.net.PlainSocketImpl.connect0(Native Method)
at java.base/java.net.PlainSocketImpl.socketConnect(PlainSocketImpl.java:101)
at java.base/java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:412)
at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:255)
at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:237)
at java.base/java.net.Socket.connect(Socket.java:608)
at java.base/java.net.Socket.connect(Socket.java:557)
at java.base/sun.net.NetworkClient.doConnect(NetworkClient.java:182)
at java.base/sun.net.www.http.HttpClient.openServer(HttpClient.java:474)
at java.base/sun.net.www.http.HttpClient$1.run(HttpClient.java:526)
at java.base/sun.net.www.http.HttpClient$1.run(HttpClient.java:524)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.base/sun.net.www.http.HttpClient.privilegedOpenServer(HttpClient.java:523)
at java.base/sun.net.www.http.HttpClient.openServer(HttpClient.java:564)
at java.base/sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:265)
at java.base/sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:372)
at java.base/sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:212)
at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1208)
at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1081)
at java.base/sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:189)
at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1592)
at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1520)
at java.base/java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:527)
at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:334)
at com.codename1.impl.javase.JavaSEPort.getResponseCode(JavaSEPort.java:10179)
at com.codename1.io.ConnectionRequest.performOperationComplete(ConnectionRequest.java:905)
at com.codename1.io.NetworkManager$NetworkThread.runCurrentRequest(NetworkManager.java:314)
at com.codename1.io.NetworkManager$NetworkThread.run(NetworkManager.java:390)
at com.codename1.impl.CodenameOneThread.run(CodenameOneThread.java:176)
'
I would like to know what is causing this and how I can fix it, Thanks.
Found the issue!
I realized I manually set proxy settings in the simulator.
Related
I get the following error when connecting to my database:
" Caused by: org.postgresql.util.PSQLException: Something unusual has occurred to cause the driver to fail. Please report this exception."
package code.with.cal.timeronservicetutorial
import kotlinx.android.synthetic.main.activity_main.*
import java.sql.DriverManager
class ConnectionHelper {
fun ConnectDB() {
val jdbcUrl = "jdbc:postgresql://HOST/USER"
// get the connection
val connection = DriverManager.getConnection(jdbcUrl, "USER", "PW")
// prints true if the connection is valid
println(connection.isValid(0))
}
}
I suspect I didn't include the dependency of right version in my gradle, but i don't know how to find which driver version i have. I added this one:
implementation 'org.postgresql:postgresql:42.2.5'
This question already has answers here:
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 4 years ago.
I am getting Java Null Pointer Exception when trying to run the below code. The test gets failed before the Web page even loads completely.
I have increased the page load timeout and Implicit wait time, but still that didn't work. The same web page is getting loaded within 4 seconds when directly launched through browser. Please find the below code:
//Loginpagetest.java
Loginpage loginpage = new Loginpage();
public LoginPageTest() throws IOException {
super();
}
#BeforeMethod
public void setup(){
initialize();
}
#Test(priority=1)
public void loginPageTitleTest(){
String actualTitle = loginpage.validateLoginPageTitle();
String expectedTitle = "#1 Free CRM software in the cloud for sales and service";
Assert.assertEquals(actualTitle,expectedTitle);
}
//TestBase.java
public void initialize(){
String browsername = prop.getProperty("browser");
if(browsername.equals("chrome")){
System.setProperty("webdriver.chrome.driver","C:\\Users\\Pranaykumar\\Downloads\\"chromedriver_win32\\chromedriver.exe");
driver = new ChromeDriver(options);
}else if(browsername.equals("mozilla")){
System.setProperty("webdriver.gecko.driver","E:\\geckodriver.exe");
driver = new FirefoxDriver();
}
driver.manage().window().maximize();
//driver.manage().deleteAllCookies();
driver.manage().timeouts().pageLoadTimeout(40, TimeUnit.SECONDS);
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.get(prop.getProperty("url"));
}
//Loginpage.java
public String validateLoginPageTitle(){
return driver.getTitle();
}
//Console
[RemoteTestNG] detected TestNG version 6.14.3
Starting ChromeDriver 2.45.615291 (ec3682e3c9061c10f26ea9e5cdcf3c53f3f74387) on port 42802
Only local connections are allowed.
[1548934220.587][WARNING]: Timed out connecting to Chrome, retrying...
Jan 31, 2019 5:00:25 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
FAILED: loginPageTitleTest
java.lang.NullPointerException
at com.crm.qa.pages.Loginpage.validateLoginPageTitle(Loginpage.java:37)
at com.crm.qa.testcases.LoginPageTest.loginPageTitleTest(LoginPageTest.java:30)
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)
The likely scenario is that you are creating a new instance of the driver inside your Loginpage page object instead of passing the existing instance so it's not initialized... thus the NPE.
Looks like this is not timeout issue, It’s showing NullPointerException. Maybe driver is null.
Check your chrome driver path is correct or not.
‘FAILED: loginPageTitleTest
java.lang.NullPointerException
at com.crm.qa.pages.Loginpage.validateLoginPageTitle(Loginpage.java:37)’
If it’s timeout issue, you should get TimeoutExcepton.
Can you please try to wait explicitly for an specific object in initialize() function and after the driver.get(prop.getProperty("url")) line as below code :
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id(objectShouldPresent)));
Kindly remove double quotes(") before chromedriver_win32
System.setProperty("webdriver.chrome.driver","C:\\Users\\Pranaykumar\\Downloads\\"chromedriver_win32\\chromedriver.exe");
Selenium Webdriver runtime Exception: unexpected alert "Please close other open tabs of the application and re-open this activity", even though there are no other tabs open.
The Automation scripts were working fine, but recently I am getting the above exception.The Screenshot of the Alert:
I tried with different versions of chrome, selenium stand alone driver, but the issue still exist. Why is this alert coming, even though the application is not open in any of the tabs or browsers other than the one execution through online?
If this pop up is coming at some specific location every time then you can simply accept it by writing below lines :
WebDriver wb=new ChromeDriver();
wb.switchTo().alert().accept();
Else if any unexpected pop up is coming ,while initializing the driver then you can use the below code :
ChromeOptions options = new ChromeOptions();
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("profile.default_content_settings.popups", 0);
String path=new GetBasePath().getPath_XML()+dir;
prefs.put("download.default_directory", path);
options.addArguments("disable-extensions");
prefs.put("credentials_enable_service", false);
prefs.put("password_manager_enabled", false);
options.setExperimentalOption("prefs", prefs);
options.addArguments("chrome.switches","--disable-extensions");
options.addArguments("--test-type");
DesiredCapabilities cap = DesiredCapabilities.chrome();
cap.setCapability(ChromeOptions.CAPABILITY, options);
cap.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.ACCEPT);
System.setProperty("webdriver.chrome.driver",**path to chromedriver.exe**"));
WebDriver wb= new ChromeDriver(cap);
My personal opinion , use both.
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.
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