newcoder1010
-
Posts
526 -
Joined
-
Last visited
Content Type
Profiles
Forums
Events
Posts posted by newcoder1010
-
-
Hello,
windows + php + xampp + mysql
https://www.w3schools.com/php/php_mysql_connect.asp
I am getting the error when I run the php script in terminal.
QuotePHP Fatal error: Uncaught Error: Class "mysqli" not found
<?php echo "<br> --- CREATE DB --- <br>"; $servername = "127.0.0.1"; $username = "root"; $password = "password"; // Create connection $conn = new mysqli($servername, $username, $password); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } echo "Connected successfully"; // Create database $sql = "CREATE DATABASE myDB"; if ($conn->query($sql) === TRUE) { echo "Database created successfully"; } else { echo "Error creating database: " . $conn->error; }
When I run the script on browser, I get this message
--- CREATE DB ---
Connected successfullyDatabase created successfullyBut when I run the script in terminal, I get an error
Stack trace:
#0 {main}
thrown in C:\xampp\w3schoolsPhp\httdocs\database-create.php on line 16
PS C:\xampp\w3schoolsPhp\httdocs> php database-create.php
<br> --- CREATE DB --- <br>PHP Fatal error: Uncaught Error: Class "mysqli" not found in C:\xampp\w3schoolsPhp\httdocs\database-create.php:16
Stack trace:
#0 {main}
thrown in C:\xampp\w3schoolsPhp\httdocs\database-create.php on line 16php.ini
/configure --with-mysqli=/path/to/mysql_config extension=bz2 extension=curl ;extension=ffi ;extension=ftp extension=fileinfo ;extension=gd extension=gettext ;extension=gmp ;extension=intl ;extension=imap ;extension=ldap extension=mbstring extension=exif ; Must be after mbstring as it depends on it extension=mysqli ;extension=oci8_12c ; Use with Oracle Database 12c Instant Client ;extension=oci8_19 ; Use with Oracle Database 19 Instant Client ;extension=odbc ;extension=openssl ;extension=pdo_firebird extension=pdo_mysql ;extension=pdo_oci ;extension=pdo_odbc ;extension=pdo_pgsql extension=pdo_sqlite ;extension=pgsql ;extension=shmop extension=php_mysql.dll
-
Hello,
Var will change dynamically. It could be one of the below in each iteration.
String var = " My name is <name="name of the person" country = "some texts" >"; String var = " My name is <name="name of the person" city = "some texts" >"; String var = " My name is <name="name of the person"country = "some texts" >"; // no space after double quotes String var = " My name is <name="name of the person"city = "some texts" >"; // no space after double quotes
How can I search and return only the following string from above variables?
name="name of the person"
Thank you!
-
Hello,
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <style> img { border-radius: 50%; } </style> </head> <body> <h2>Rounded Images</h2> <img src="/sites/default/files/2022-12/bg-house.png" alt="Avatar" style="width:200px"> </body> </html>
Original image
Round image after styling. It looks oval shape.
How can I round the image like this one in below?
https://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_rounded_images
-
Hello,
I would like to style a call now block like the one below
Here is my HTML:
<span class="glyphicon glyphicon-earphone"></span> <a href="tel:(000)926-4444" class="phone">Call Now!</a>
It does not have to be exactly the same as the image. Something close to the image would be helpful.
Thank you!
-
I made some progress but not working yet. Its not reaching the block of code inside the loop
LocalDateTime timeNow = java.time.LocalDateTime.now(); System.out.println( "timeNow "+ timeNow); LocalDateTime newtime = timeNow.plusMinutes(5); System.out.println( "newtime "+ newtime); Thread.sleep(5000); while(newtime.equals(timeNow)) { Thread.sleep(5000); timeNow = java.time.LocalDateTime.now(); System.out.println( "timeNow "+ timeNow); } System.out.println( "timeNow exited at "+ timeNow);
-
Hello,
I like to add 5 minutes to current system time. After adding 5 minutes to the current time, I like to have a loop which will keep checking until system time has changed to the new time.
Lets say now is 11:50:01AM
Add 5 minutes to current time. So new time would be 11:55:01AM
I like to have a loop which will keep checking if system time is 11:55:01AM. If yes, exit the loop.
I started working on it but I am not quit there yet.
LocalDateTime timeNow; while(???) { Thread.sleep(6666); timeNow = java.time.LocalDateTime.now(); }
Can you help?
-
Hello,
Base.java
package JavaTestNG; import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeTest; public class Base { public int x; // Invoked once when I run the xml file @BeforeTest public void beforeTest() { x=9; } // invoked once for every class @BeforeClass public void beforeClass() { System.out.println("beforeClass"); } }
Test1.java
import org.testng.annotations.Test; public class Test1 extends Base{ @Test public void test1() { System.out.println("test 1"); System.out.println("x " + x); } }
Test2.java
import org.testng.annotations.Test; public class Test2 extends Base{ @Test public void test2_1() { System.out.println("test2_1"); System.out.println("x " + x); } }
Test3.java
import org.testng.annotations.Test; public class Test3 extends Base{ @Test public void test3_1() { System.out.println("test3_1"); System.out.println("x " + x); } }
XML:Running the xml file
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd"> <suite name="test"> <test name="Test1"> <classes> <class name="JavaTestNG.Test1" /> <class name="JavaTestNG.Test2" /> </classes> </test> <test name="Test2"> <classes> <class name="JavaTestNG.Test3" /> </classes> </test> </suite>
Console
[RemoteTestNG] detected TestNG version 7.4.0
beforeClass
test 1
x 9
beforeClass
test2_1
x 0
beforeClass
test3_1
x 9
---
As you can see, I am getting x 0 for the second test. I am not sure why x = 0 for the second test. Instead, I was expecting to have the value of 9. Can you please help?
-
Hello,
First Test:
public class FirstTest extends GridSessionBase { @Test public void test1() { System.out.println("First test"); printSessionThreadID(); } }
Second Test:
public class SecondTest extends GridSessionBase{ @Test public void test1() { System.out.println("Second test"); printSessionThreadID(); } }
Base:
public class GridSessionBase{ WebDriver driver; // invoked once before executing each @Test method @BeforeMethod public void beforeMethod(Method method) { System.setProperty("webdriver.chrome.driver", "Automation_Tools\\ChromeDriver\\chromedriver.exe"); driver = new ChromeDriver(); System.out.println("beforeMethod"); SessionId s = ((RemoteWebDriver) driver).getSessionId(); System.out.println("Before method session ID: " + s); long id = Thread.currentThread().getId(); System.out.println("Before method thread ID: " + id); } // all the tests are calling this method. public synchronized void printSessionThreadID() { System.out.println("printSessionThreadID"); SessionId s = ((RemoteWebDriver) driver).getSessionId(); System.out.println("Session ID: " + s); long id = Thread.currentThread().getId(); System.out.println("Thread ID: " + id); // if session id and thread id match // if() { // // print class name and test method name of the caller // } } }
XML file to run the tests in parallel:
Below I have two <test> tags. It means all the TestNG methods listed in each <test> tag will run in the same thread. Test1 will run in one thread and Test2 will run in another thread. Both <test> tags will run in parallel.
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd"> <suite name="Access Regression Suite" parallel="tests"> <test name="Test1"> <classes> <class name="GridSessionJava.FirstTest"/> </classes> </test> <test name="Test2"> <classes> <class name="GridSessionJava.FirstTest" /> <class name="GridSessionJava.SecondTest" /> </classes> </test> </suite>
When I run xml file, here is the output:
QuotebeforeMethod
beforeMethod
Before method session ID: 9b993ec9e1e67b2dd9775d398ed974fb
Before method session ID: 7261a9b1dbadaf149f72b38c4355375e
Before method thread ID: 18
Before method thread ID: 19
First test
printSessionThreadID
Session ID: 9b993ec9e1e67b2dd9775d398ed974fb
Thread ID: 18
First test
printSessionThreadID
Session ID: 7261a9b1dbadaf149f72b38c4355375e
Thread ID: 19
Starting ChromeDriver 105.0.5195.52 (412c95e518836d8a7d97250d62b29c2ae6a26a85-refs/branch-heads/5195@{#853}) on port 59998
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
Sep 26, 2022 9:54:19 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected upstream dialect: W3C
Sep 26, 2022 9:54:19 AM org.openqa.selenium.devtools.CdpVersionFinder findNearestMatch
WARNING: Unable to find an exact match for CDP version 105, so returning the closest version found: 104
Sep 26, 2022 9:54:19 AM org.openqa.selenium.devtools.CdpVersionFinder findNearestMatch
INFO: Found CDP implementation for version 105 of 104
beforeMethod
Before method session ID: 6ca9632512259997c7c59c02509892fb
Before method thread ID: 19
Second test
printSessionThreadID
Session ID: 6ca9632512259997c7c59c02509892fb
Thread ID: 19printSessionThreadID() is being called three times. In printSessionThreadID() method, I like to know which test is calling this method. How do I write if statement in printSessionThreadID() method to check if session ID and thread ID match(or just matching thread ID) and print a message afterward?
-
Thank you!
-
To summerize, I am setting the logger before every test method. Then trying to get the logger from another class.
-
<!-- https://mvnrepository.com/artifact/com.relevantcodes/extentreports --> <dependency> <groupId>com.relevantcodes</groupId> <artifactId>extentreports</artifactId> <version>2.41.2</version> </dependency>
BaseTest
public class BaseTest extends Base{ public static ExtentReports reporter; public ExtentTest loggerParent = null; // invoked once before I run one or more tests @BeforeSuite public void initializeReport(){ reporter = new ExtentReports("ExtentReport6.html", true, DisplayOrder.OLDEST_FIRST); } // invoked before every @Test method @BeforeMethod public synchronized void beforeMethod(Method method) { System.out.println("beforeMethod"); logger = reporter.startTest(method.getName()); loggerParent.appendChild(logger); setLogger(logger); logger.log(LogStatus.INFO, "before method"); } @BeforeClass public void beforeClass() throws MalformedURLException { ITestResult itr = Reporter.getCurrentTestResult(); String className = itr.getInstance().getClass().getName(); loggerParent = reporter.startTest(className); loggerParent.log(LogStatus.INFO, "Before class"); } @AfterSuite public void afterSuite() { reporter.flush(); } }
Base
package Base; import com.relevantcodes.extentreports.ExtentTest; public class Base { public ExtentTest logger = null; public void setLogger(ExtentTest logger1) { this.logger = logger1; } public synchronized ExtentTest getLogger() { return logger; } }
DataDriven
public class DataDriven extends Base{ public synchronized void launchExcelFile(String fileNameWithExtension, String sheetName) { logger.log(LogStatus.INFO, "launch excel"); }}
@Test
public class CreateAccount extends BaseTest2 { @Test public void test1() { logger.log(LogStatus.INFO, "create account test8"); DataDriven dataDriven = new DataDriven(); dataDriven.launchExcelFile("TestData.xls", "profiles"); }}
Error when I run the test:
Quotejava.lang.NullPointerException: Cannot invoke "com.relevantcodes.extentreports.ExtentTest.log(com.relevantcodes.extentreports.LogStatus, String)" because "this.logger" is null
Error is from this line in DataDriven.javalogger.log(LogStatus.INFO, "launch excel");
I spent all day but could not fix it yet. I am just not sure how to use the logger in DataDriven file. Thank you in advance!
-
Thanks for your reply.
I am trying to set name from one class and be able to get name from another class.
As you can see, I have set name in @Test method from CreateAccount class
.
setName("Mike");
I am trying to get the same name from GetData class. How can I do it?
-
Hello,
public class Base { public String name = null; public String getName() { return name; } public void setName(String myName) { this.name = myName; } }
GetData
public class GetData extends Base{ public String GetMyData() { return getName(); } }
Test:
public class CreateAccount extends Base { @Test public void test1() { setName("Mike"); String name = getName(); System.out.println("get name: " + name); // get the value "Mike" GetData getData = new GetData(); name = getData.GetMyData(); System.out.println("get name: " + name); // get null } }
Output:
Quoteget name: Mike
get name: nullI expected to get "Mike" both cases but I am getting null second time.
I could fix it by writing static but I am doing some parallel testing. How can I fix it without writing static?
public static String name = null;
-
Hello,
Maven dependency:
<dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> <version>1.4.0</version> </dependency>
Main method
public class HelloMain { private final static Logger log = LoggerFactory.getLogger(HelloMain.class); public static void main(String[] args) { log.info("hello"); } }
When I run the program in IntelliJ, I get the error on the following line:
private final static Logger log = LoggerFactory.getLogger(HelloMain.class);
Quotech/qos/logback/classic/spi/LogbackServiceProvider has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
I fixed it by changing the dependency version:
<dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> <version>1.3.0</version> </dependency>
Java on my pc:
C:\Users\sa>java -version java version "1.8.0_341" Java(TM) SE Runtime Environment (build 1.8.0_341-b10) Java HotSpot(TM) 64-Bit Server VM (build 25.341-b10, mixed mode)
Could you please explain me why I got the error first place? Why changing the version of logback fixed the problem? I am bit confused with java compiler, JDK, JRE, and Dependency version.
If you could include an example, it would help. I am new to Spring framework.
Thank you!
-
Thank you! Worked just fine.
-
Hello,
String words = "I go to summer school. I also go to winter school"; int counter = 0; if(words.contains("go to")) { counter++; } System.out.println("counter " + counter);
As you can see "go to" is repeated twice. I like the counter to return the value of 2. But it returns 1. How can I count the duplicate words?
-
Hello,
https://www.w3schools.com/java/java_threads.asp
public class Main extends Thread { public static void main(String[] args) { Main thread = new Main(); thread.start(); System.out.println("This code is outside of the thread"); } public void run() { System.out.println("This code is running in a thread"); } }
I am not able to understand two
System.out.println("This code is outside of the thread"); System.out.println("This code is running in a thread");
messages. How does one is running outside of the thread and another is running in a thread? If you clarify a bit more(with an example) what is running in a thread and what is running outside of a thread.
Thanks!
-
Hello
I am doing annotation first time.
package annotationsPractice; import java.lang.annotation.Documented; import java.lang.annotation.Retention; import java.lang.annotation.Target; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.ElementType; @Documented @Retention(RetentionPolicy.RUNTIME) @Target({ ElementType.TYPE, ElementType.METHOD, ElementType.PARAMETER, ElementType.FIELD }) public @interface CustomAnnotation { public enum MYAPPS { app1, app2, noSet } public enum AUTHORS { john, mike, noSet } String ID() default "null"; AUTHORS AUTHOR() default AUTHORS.noSet; MYAPPS APP() default MYAPPS.noSet; }
ClassA
package annotationsPractice; import annotationsPractice.CustomAnnotation.AUTHORS; public class classA extends classB{ @CustomAnnotation(ID = "100", APP = CustomAnnotation.MYAPPS.app1, AUTHOR = AUTHORS.mike) public static void main(String[] args) { // TODO Auto-generated method stub System.out.println("main"); getAnnotationAttributes(); } }
classB
package annotationsPractice; import java.lang.annotation.Annotation; import com.sun.jdi.Method; import annotationsPractice.CustomAnnotation.AUTHORS; public class classB { public static void getAnnotationAttributes() { java.lang.reflect.Method[] methods = classA.class.getMethods(); String id = methods.getClass().getAnnotation(CustomAnnotation.class).ID(); System.out.println("id " + id); } }
When I run ClassA, I was expecting to see annotation attributes in ClassB. How do I get the attribute values (ID = "100") in ClassB when I run Class A?
-
Hello,
Test
public class AnnotationTest extends Base{ @storyInfo(ID = "Story 1") public static void main(String[] args) { // TODO Auto-generated method stub System.out.println("First annotation ever"); } }
Code
@Documented @Retention(RetentionPolicy.RUNTIME) @Target({ ElementType.TYPE, ElementType.METHOD, ElementType.PARAMETER, ElementType.FIELD }) public @interface storyInfo { String ID(); }
Base
public class Base { // How to read the value of ID attribute everytime I run main }
Every time I run main method, how can retrieve the value of ID in Base?
-
-
Hello
config.properites file browser = chrome
LoadConfig.java file public class LoadConfig{ public static String BrowserType = null; public static boolean load() throws Exception { Properties envProps = new Properties(); envProps.load(new FileInputStream(ConfigFile)); BrowserType = envProps.getProperty("browserType"); // it should get the value from config.properties file } }
Test
public static void main(String[] args) throws IOException { System.out.println(LoadConfig.BrowserType); }
I get null when I run my main method instead I like to see the value "chrome" from the config.properties file. How can I get the value of chrome when I run main method?
-
Hello,
// for loop 1 for(int i = 0; i < 1000; i++) { // it will collect some data ( each set of data will have int, string, boolean, string, int) i.e. empNo, empTitle, isGraduated, city, yearGraduated // I like to collect all the data into some array or array list or collection (need some recommendation without using database) .so I can iterate thru the // records during run time later in the steps } // for loop 2 // I like to iterate thro all the records that I temporarily stored in a list in for loop 1 for(int i = 0; i < 1000; i++) { // read data row by row }
I am not sure how to do this program. Can you please help?
-
Hello,
package application.controller; import com.jfoenix.controls.JFXButton; import com.jfoenix.controls.JFXPasswordField; import com.jfoenix.controls.JFXTextField; import java.net.URL; import java.util.ResourceBundle; import javafx.fxml.FXML; import javafx.scene.Node; import javafx.scene.control.Label; import javafx.scene.layout.AnchorPane; import javafx.event.ActionEvent; public class LoginController { @FXML private ResourceBundle resources; @FXML private URL location; @FXML private AnchorPane mainContainer; @FXML private AnchorPane loginContainer; @FXML private Label label; @FXML private JFXTextField userName; @FXML private JFXPasswordField password; @FXML private JFXButton loginButton; @FXML void initialize() { loginButton // pressing dot after loginButton does not display setOnAction event } }
How can I use the setOnAction event for the loginButton?
Thanks!
-
Now it makes sense. Thank you!
How to vertically aligninginput text field to top ?
in CSS
Posted · Edited by newcoder1010
Hello,
CSS
input { height:100px; background: green; vertical-align: top; }
Tried below as well but it did not work.
padding-top:0px
https://ibb.co/Fwsmgj2
How can I vertically align all the input text fields to top?