|
Start by learning the basics by reading books, doing tutorials, watching videos, etc. Then, I would suggest making some application. I learn best by doing so I'd make some sort of app.
|
|
|
|
|
|
Hello everyone
I'm trying to pass the matchday to the URL for the Http connection. I know I can't get a value from the EditText in the doInBackground method so I thought to get the value in the onPreExecute method. Of I then add the variable to the URL, the program doesn't recognise the String. I saw on StackOverflow you need to add the parameters in the execute method but I don't really have got that part of the explanation.
Does anyone have an idea how to add the matchday to the URL, entered in the EditText matchdayText?
Thanks in advance!
|
|
|
|
|
I have two different XML documents below and please note that they are having the same basic structure (schema).
Source XML
<root>
<name>String</name>
<description>String</description>
</root>
Test XML
<root>
<name>Test</name>
<description></description>
</root>
And I build this snippet function to compare those two XML documents.
import org.custommonkey.xmlunit.Diff;
import org.custommonkey.xmlunit.Difference;
import org.custommonkey.xmlunit.IgnoreTextAndAttributeVal uesDifferenceListener;
import org.custommonkey.xmlunit.XMLUnit;
public static void main(String args[]) throws FileNotFoundException,
SAXException, IOException, ParserConfigurationException, XPathExpressionException {
String strSource = "<root><name>String</name><description>String</description></root>";
String strTest = "<root><name>Test</name><description></description></root>";
Document docSource = stringToXMLDocument(strSource);
Document docTest = stringToXMLDocument(strTest);
boolean result = isMatched(docSource, docTest);
if(result){
System.out.println("Matched!");
}else{
System.out.println("Un-matched!");
}
}
public static boolean isMatched(Document xmlSource, Document xmlCompareWith) {
XMLUnit.setIgnoreWhitespace(true);
XMLUnit.setIgnoreComments(true);
XMLUnit.setIgnoreAttributeOrder(true);
XMLUnit.setNormalizeWhitespace(true);
XMLUnit.setIgnoreDiffBetweenTextAndCDATA(true);
Diff myDiff = new Diff(xmlSource, xmlCompareWith);
myDiff.overrideDifferenceListener(new IgnoreTextAndAttributeValuesDifferenceListener());
return myDiff.similar();
}
public static Document stringToXMLDocument(String str) throws ParserConfigurationException, SAXException, IOException{
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
docBuilderFactory.setNamespaceAware(true);
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
Document document = docBuilder.parse(new InputSource(new StringReader(str)));
return document;
}
And here is the Maven dependency
<dependency>
<groupId>xmlunit</groupId>
<artifactId>xmlunit</artifactId>
<version>1.6</version>
</dependency>
I am expecting those two XML documents are the same, but the function always returns false. Are there any ways that I can ignore the node text value when comparing two XML structures? As you can see, I already used IgnoreTextAndAttributeValuesDifferenceListener, but I still got the problem.
|
|
|
|
|
You are more likely to get help from the owners of the XMLUnit package.
|
|
|
|
|
How to generate and validate a software license key using java
|
|
|
|
|
import java.util.Scanner;
import java.io.*;
public class ReadFirstLine
{
public static void main(String[] args) throws IOException
{
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter the name of a file: ");
String filename = keyboard.nextLine();
File file = new File(filename);
Scanner inputFile = new Scanner(file);
String line = inputFile.nextLine();
System.out.println("The first line in the file is:");
System.out.println(line);
inputFile.close();
}
}
Enter the name of a file: MyFriends.txt
Exception in thread "main" java.io.FileNotFoundException: MyFriends.txt (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.jav a:138)
at java.util.Scanner.<init>(Scanner.java:611)
at ReadFirstLine.main(ReadFirstLine.java:21)
Java Result: 1
|
|
|
|
|
Enter the full path of the file, not just its name.
|
|
|
|
|
I am tryin to write the result of the pdf validation in to an excel but it is not working can anyon help below is the code i wrote
<pre>public static void PDF_File_Validation(String object, String data) throws IOException{
try{
Log.info("PDF Documents has been Verified");
List<String> outputs = new ArrayList<String>();
System.setProperty("webdriver.chrome.driver", Constants.Path_driver);
WebDriver driver = new ChromeDriver();
File[] files = new File(object).listFiles(File::isFile);
for (File file: files) {
String fileExtension = file.getName().split("\\.")[file.getName().split("\\.").length - 1];
if (fileExtension.toLowerCase().equals("pdf")) {
String fileUrl = "file:///" + file.getAbsolutePath();
driver.get(fileUrl);
URL url = new URL(driver.getCurrentUrl());
InputStream is = url.openStream();
BufferedInputStream fileToParse = new BufferedInputStream(is);
PDDocument document = null;
String output;
try {
document = PDDocument.load(fileToParse);
output = new PDFTextStripper().getText(document);
} finally {
if (document != null) {
document.close();
}
fileToParse.close();
is.close();
}
outputs.add(output);
Thread.sleep(2500);
boolean test = output.contains(data);
String test1=Boolean.toString(test);
FileInputStream file1 = new FileInputStream(Constants.Path_Result+DriverScript.s+"\\PDFResults.xlsx");
@SuppressWarnings("resource")
XSSFWorkbook workbook = new XSSFWorkbook(file1);
XSSFSheet sheet = workbook.getSheetAt(0);
Row row1 = sheet.createRow( 0 );
if (test1.contains("false")){
Log.info("The "+file.getName()+" File does not Contain "+ data+"="+"Failed");
}else{
Log.info("The "+file.getName()+" File Containes "+ data+"="+"Passed");
}
for ( int cellIndex = 0; cellIndex < output.length(); cellIndex++ ) {
Cell cell = row1.createCell( cellIndex );
if (test1.contains("false")){
cell.setCellValue("The "+file.getName()+" File does not Contain "+ data+"="+"Failed");
}else{
cell.setCellValue("The "+file.getName()+" File Containes "+ data+"="+"Passed");
}
}
file1.close();
FileOutputStream outFile =new FileOutputStream(Constants.Path_Result+DriverScript.s+"\\PDFResults.xlsx");
workbook.write(outFile);
outFile.close();
}}
driver.quit();
return;
}catch(Exception e){
Log.error("PDF Documents was not Verified --- " + e.getMessage());
DriverScript.bResult = false;
}
}
|
|
|
|
|
Member 13938502 wrote: but it is not working Please exlain what that means.
|
|
|
|
|
I am tryin to write the result of the pdf validation in to an excel but it is not working can anyon help below is the code i wrote
<pre>public static void PDF_File_Validation(String object, String data) throws IOException{
try{
Log.info("PDF Documents has been Verified");
List<String> outputs = new ArrayList<String>();
System.setProperty("webdriver.chrome.driver", Constants.Path_driver);
WebDriver driver = new ChromeDriver();
File[] files = new File(object).listFiles(File::isFile);
for (File file: files) {
String fileExtension = file.getName().split("\\.")[file.getName().split("\\.").length - 1];
if (fileExtension.toLowerCase().equals("pdf")) {
String fileUrl = "file:///" + file.getAbsolutePath();
driver.get(fileUrl);
URL url = new URL(driver.getCurrentUrl());
InputStream is = url.openStream();
BufferedInputStream fileToParse = new BufferedInputStream(is);
PDDocument document = null;
String output;
try {
document = PDDocument.load(fileToParse);
output = new PDFTextStripper().getText(document);
} finally {
if (document != null) {
document.close();
}
fileToParse.close();
is.close();
}
outputs.add(output);
Thread.sleep(2500);
boolean test = output.contains(data);
String test1=Boolean.toString(test);
FileInputStream file1 = new FileInputStream(Constants.Path_Result+DriverScript.s+"\\PDFResults.xlsx");
@SuppressWarnings("resource")
XSSFWorkbook workbook = new XSSFWorkbook(file1);
XSSFSheet sheet = workbook.getSheetAt(0);
Row row1 = sheet.createRow( 0 );
if (test1.contains("false")){
Log.info("The "+file.getName()+" File does not Contain "+ data+"="+"Failed");
}else{
Log.info("The "+file.getName()+" File Containes "+ data+"="+"Passed");
}
for ( int cellIndex = 0; cellIndex < output.length(); cellIndex++ ) {
Cell cell = row1.createCell( cellIndex );
if (test1.contains("false")){
cell.setCellValue("The "+file.getName()+" File does not Contain "+ data+"="+"Failed");
}else{
cell.setCellValue("The "+file.getName()+" File Containes "+ data+"="+"Passed");
}
}
file1.close();
FileOutputStream outFile =new FileOutputStream(Constants.Path_Result+DriverScript.s+"\\PDFResults.xlsx");
workbook.write(outFile);
outFile.close();
}}
driver.quit();
return;
}catch(Exception e){
Log.error("PDF Documents was not Verified --- " + e.getMessage());
DriverScript.bResult = false;
}
}
modified 11-Feb-21 11:41am.
|
|
|
|
|
Start by reading what it says at the top of the page: this is not the place for programming enquiries.
Try here: Ask a Question[^]
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
This is not the place to ask your question. See above:
Quote: Got a programming question?
Get me coffee and no one gets hurt!
|
|
|
|
|
this is not the place to ask programming questions. see above comments telling you to see above.
basically just walk around all day and look above you.
good luck in the QA forum(s).
|
|
|
|
|
Slacker007 wrote: walk around all day and look above you. that's a sure fire way to fall in a hole.
|
|
|
|
|
I keep reading this as "How to write excellent insults with JavaScript."
I bet people would answer that programming question in the lounge!
|
|
|
|
|
package p_food;
public class Eat {
public static void main(String[] args){
Candy object1 = new Candy();
Choc object2 = new Choc();
object1.print();
}
}
package p_food;
import javax.swing.*;
class candy {
static void main(String args[]){
String flavor;
String dTaste;
String candy;
public void print(){
JOptionPane.showMessageDialog(null, + candy + " " + flavor + " " + dTaste + " " + "taste sweet like you, You bring me so much joy...");
}
}
package p_food;
import javax.swing.*;
class Choc {
static void main(String args[]){
String flavor;
String dTaste;
public void print(){
JOptionPane.showMessageDialog(null, + "but...." + " " + flavor + " " + dTaste + " " + "taste sweet like you, You bring me so much joy...");
}
}
}
import javax.swing.*;
class Confectionary {
double calorie;
String flavour;
String dTaste;
public void print(){
JOptionPane.showMessageDialog(null, +dTaste+" "+candy+" "+"candy taste nice!");
}
}
package p_food;
class Food {
static void main(String args[]){
double reading;
String dTaste;
}
}
HOW CAN I MAKE IT INTO 1 PROGRAM CODE?
|
|
|
|
|
That code really does not make much sense. I suggest you go to The Java™ Tutorials[^], and work through them.
|
|
|
|
|
Im self studying and purchased the ap book. I don't understand the following question:
consider a b c are integers consider this boolean expression
(a < b ) || !(( c==a * b)) && (c < a )
the answer is
c < a is false
would someone please explain HOW thats the answer? tysm
|
|
|
|
|
Ap_noob wrote: HOW thats the answer? It's not the answer. The answer will depend on the values of a, b and c.
|
|
|
|
|
If you have String array arr = {"145", "457", "784", "258"}, is there any other quicker way to convert each element of the array to Integer without using any loop? The below approach can work, but it will require each element to be explicitly converted to Integer.
myIntArray = new int[arr.length];
For(for int i=0; i
|
|
|
|
|
What is wrong for you with using the loop?
|
|
|
|
|
Azbilegt Chuluunbat wrote: is there any other quicker way to convert each element of the array to Integer without using any loop No.
Azbilegt Chuluunbat wrote: it will require each element to be explicitly converted to Integer. Well that is true whether you use a loop or not.
|
|
|
|
|
The fact that your byte array would perfectly fit into a __m128i makes me wonder if that is a homework question. I am not a Java programmer so I have no idea if it is even possible in Java. However with C you could parse it in-place with SSSE3:
#include <emmintrin.h>
#include <intrin.h>
CHAR source_array[4][4] = { "145", "457", "784", "258" };
INT target_array[4] = { 0, 0, 0, 0 };
__m128i target = _mm_loadu_si128(reinterpret_cast<__m128i *>(source_array));
__m128i subtract_me = _mm_set1_epi8('0');
__m128i numbers_array = _mm_subs_epu8(target, subtract_me);
__m128i mul_deci = _mm_setr_epi8(10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1);
__m128i deci = _mm_maddubs_epi16(numbers_array, mul_deci);
__m128i mul_centi = _mm_setr_epi16(100, 1, 100, 1, 100, 1, 100, 1);
__m128i centi = _mm_madd_epi16(deci, mul_centi);
target_array[0] = centi.m128i_i16[0]/10;
target_array[1] = centi.m128i_i16[2]/10;
target_array[2] = centi.m128i_i16[4]/10;
target_array[3] = centi.m128i_i16[6]/10;
Maybe a Java programmer can let us know if SIMD intrinsics can be translated into Java.
Best Wishes,
-David Delaune
|
|
|
|
|
Can anyone help me figure this out? I wrote the following code for my programming class.
package weekthreeassignments;
public class Odds {
public static void main(String[] args) {
int product = 1;
for (int i = 1; i <= 15; i++)
if (i % 2 == 1) {
product *= i;
}
System.out.println("Product of the odd integers from 1 to 15 is: " + product);
}
}
When I run the code I get the following error and how to fix it, but if you read the "Please define" part, I did define it that way. Why am I still erroring?
Error: Main method not found in class weekthreeassignments.Odds, please define the main method as:
public static void main(String[] args)
or a JavaFX application class must extend javafx.application.Application
C:\Users\fred\AppData\Local\NetBeans\Cache\10.0\ex ecutor-snippets\run.xml:111: The following error occurred while executing this line:
C:\Users\fred\AppData\Local\NetBeans\Cache\10.0\ex ecutor-snippets\run.xml:68: Java returned: 1
BUILD FAILED (total time: 0 seconds)
|
|
|
|