|
I'm trying to find a file based on the starting eight digits extracted from an excel sheet for every iteration. I am receiving the error notice "Local variable CaseID declared in an enclosing scope must be final or effectively final" so i am using the code below and still appears to be fresh, so I don't know how to correct this, Even after it happen to be a straightforward repair.
package Chrome;
import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FilenameFilter;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.DataFormatter;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
public class ValidateInput {
public static void main(String[] args) throws Throwable {
File src = new File("C:\\Users\\Z246379\\Documents\\TestDataFolder\\ValidateInput.xlsx");
FileInputStream fis = new FileInputStream(src);
XSSFWorkbook wb = new XSSFWorkbook(fis);
XSSFSheet Sheet1 = wb.getSheetAt(0);
int i1 = 2;
String data0 = Sheet1.getRow(2).getCell(0).getStringCellValue();
String data01 = Sheet1.getRow(2).getCell(1).getStringCellValue();
String caseID = Sheet1.getRow(i1).getCell(2).getStringCellValue();
String Desc = Sheet1.getRow(2).getCell(3).getStringCellValue();
String ICF = Sheet1.getRow(1).getCell(4).getStringCellValue();
String CRPT = Sheet1.getRow(1).getCell(5).getStringCellValue();
System.out.println("Called openBrowser");
String exePath = System.getProperty("user.dir")+"\\chromedriver.exe";
System.setProperty("webdriver.chrome.driver", exePath);
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("useAutomationExtension", false);
options.addArguments("start-maximized");
options.addArguments("--no-sandbox");
options.addArguments("--disable-extensions-except");
options.addArguments("disable-extensions");
WebDriver driver = new ChromeDriver(options);
driver.get("https://client.abc.com");
driver.findElement(By.xpath("//input[@id='userid']")).sendKeys(data0);
driver.findElement(By.xpath("//body[@class='no-nav']/div[@id='wrapper']/header[@class='header']/div[@class='container']/div[@class='menu']/div[@class='drop']/div[@class='login-form']/form[@method='POST']/div[2]/input[1]")).sendKeys(data01);
driver.findElement(By.xpath("//input[@value='Sign In']")).click();
Thread.sleep(2000);
driver.findElement(By.xpath("//span[@class='wpsNavLevel2'][contains(text(),'EZ-Test')]")).click();
Thread.sleep(3000);
driver.get("https://ezt.abc.com/Test/inputFiles/selectValidateInput/selectValidateInput.xhtml");
while (caseID != null)
{
caseID = Sheet1.getRow(i1).getCell(2).getStringCellValue();
driver.findElement(By.xpath("//input[@id='mainForm:caseId']")).sendKeys(caseID);
driver.findElement(By.xpath("//input[@id='mainForm:testBedDesc']")).sendKeys(Desc);
driver.findElement(By.xpath("//select[@id='mainForm:customRptOptions']")).sendKeys(ICF);
driver.findElement(By.xpath("//span[@id='mainForm:customReportLabel']")).click();
File dir = new File("C:\\Users\\Z333379\\Documents\\Test beds");
FilenameFilter filter = new FilenameFilter() {
public boolean accept (File dir, String name) {
return name.startsWith(caseID);
}
};
String[] children = dir.list(filter);
if (children == null) {
System.out.println("Either dir does not exist or is not a directory");
} else {
for (int i=0; i< children.length; i++) {
String filename = children[i];
System.out.println(filename);
driver.findElement(By.xpath("//input[@id='mainForm:comprehensive']")).sendKeys("C:\\Users\\Z246379\\Documents\\Test beds\\" + filename);
}
}
driver.findElement(By.xpath("//button[@id='mainForm:reset']")).click();
i1=i1+1;
}
}
}
This is from the source I read, I don't know how to define an inner local class with a mutable variable. Is that correct? This problem appears to be at the bottom of the code, at the caseID variable.
modified 3-Jan-23 7:15am.
|
|
|
|
|
Try this:
final String caseId1 = caseID;
FilenameFilter filter = new FilenameFilter() {
public boolean accept (File dir, String name) {
return name.startsWith(caseId1);
}
};
|
|
|
|
|
i want to locate a file based on the first eight digits extracted from an excel sheet for every iteration. I am receiving the error notice "Local variable CaseID declared in an enclosing scope must be final or effectively final" so i am using a code below and it still showing it as fresh, and i dont know how to correct it, even after it appears to be a straightforward repair.
|
|
|
|
|
Without seeing your actual code it is difficult to make any useful suggestions. Please edit your question and show the relevant code and explain where the error occurs.
|
|
|
|
|
|
Hello everyone, I have a list of Objects, whose attributes include a BLOB object, taken from a database, how can I display the image in JSP?
This is the servlet code with which I take objects from the DB
<pre lang="Java">
while(rs.next()) {
Rapportino rapp = new Rapportino();
String nome_operaio = rs.getString("nome_operaio");
String cognome_operaio = rs.getString("cognome_operaio");
String ruolo_operaio = rs.getString("ruolo_operaio");
Date data = rs.getDate("data");
String luogo = rs.getString("luogo");
Blob foto = rs.getBlob("file");
rapp.setNome_operaio(nome_operaio);
rapp.setCognome_operaio(cognome_operaio);
rapp.setRuolo_operaio(ruolo_operaio);
rapp.setData(data);
rapp.setLuogo(luogo);
rapp.setFoto(foto);
rapportini.add(rapp);
}
request.setAttribute("rapportini", rapportini);
request.getRequestDispatcher("rapportino.jsp").forward(request,response);
And this is the jsp, for now I have not implemented the code for the BLOB
<pre lang="HTML"><pre>
<% List<Rapportino> rapportini = (List<Rapportino>)request.getAttribute("rapportini");%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Rapportini</title>
</head>
<body>
<h1>Rapportino:</h1>
<table>
<c:forEach items="${rapportini}" var="rapp">
<tr>
<td><c:out value="${rapp}" /></td>
</tr>
</c:forEach>
</table>
<a href="homepage_admin.jsp">Torna alla home</a>
</body>
</html>
|
|
|
|
|
Above is too confusing.
Your goal is to display an image (not a blob) which comes from a database
1. Read the blob into a memory representation
2. Figure out how to display an image, ANY image. Perhaps hard code one for testing
3. Figure out how to convert data from 1 to what you need for step 2.
Step 1 and Step 2 are INDEPENDENT. Do one then the other. Do not try to do both at the same time.
|
|
|
|
|
|
There is no 'best', there are just choices. So start by looking at the features available in any of the languages that you are familiar with. If you are not familiar with any languages then you need to think about some study materials.
|
|
|
|
|
Looking at his profile and message history, he's a spammer trying to push his food delivery app.
Spammer (nithin sethu)[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks. And I have a feeling I flagged him already the other day.
|
|
|
|
|
Which part?
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
1) Un negocio de perfumería efectúa descuentos en sus ventas según el importe de éstas, con la siguiente escala:
- Si el importe es menor a $100 corresponde un descuento del 5%
- Si el importe es de entre $100 (inclusive) y hasta $500 (inclusive) corresponde un
descuento del 10%
- Si el importe es mayor a $500 corresponde un descuento del 15%
El dueño le solicitó a Ud., futuro programador, un programa donde se deba ingresar el importe original a pagar por el cliente y que luego se calcule e informe por pantalla el precio final con el descuento que corresponda ya aplicado.
2) Hacer un programa para ingresar por teclado la nota obtenida por un alumno en una determinada materia y luego emitir el cartel aclaratorio que corresponda, de acuerdo a las siguientes condiciones:
- “Sobresaliente”, si la nota fue 10.
- “Distinguido”, si la nota fue 9 ó 8.
- “Bueno”, si la nota fue 7 ó 6.
- “Aprobado”, si la nota fue 5 ó 4.
- “Insuficiente”, si la nota fue 3, 2 ó 1.
- “Ausente”, si la nota fue 0.
7) Hacer un programa para ingresar por teclado las cuatro notas de los exámenes parciales obtenidas por un alumno en una determinada materia y luego emitir el cartel aclaratorio que corresponda, de acuerdo a las siguientes condiciones:
- “Promociona”, si obtuvo en los cuatro exámenes nota 7 o más.
- “Rinde examen final”, si obtuvo nota 4 o más en por lo menos tres exámenes.
- “Recupera Parciales”, si obtuvo nota 4 o más en por lo menos uno de los exámenes.
- “Recursa la materia”, si no aprobó ningún examen parcial.
modified 3-Dec-22 19:11pm.
|
|
|
|
|
We won't do your home work for you, but you could at least write it in English.
|
|
|
|
|
I have this problem where I solved it when my array is not empty.
My issue is whem the array is empty. I tried to put an condition but it's useless.
I got this error "[ERROR] CycleSwapTest.testCycleSwapEmptyCaseShift:44 � ArrayIndexOutOfBounds Index 0 o..."
Proceed to CycleSwap class and implement its static methods:
void cycleSwap(int[] array)
Shifts all the elements in the given array to the right by 1 position.
In this case, the last array element becomes first.
For example, 1 3 2 7 4 becomes 4 1 3 2 7.
void cycleSwap(int[] array, int shift)
Shift all the elements in the given array to the right in the cycle manner by shift positions.
Shift value is guaranteed to be non-negative and not bigger than the array length.
For example, 1 3 2 7 4 with a shift of 3 becomes 2 7 4 1 3.
For a greater challenge, try not using loops in your code (not mandatory).
Note that input array may be empty.
Examples
Code Sample:
int[] array = new int[]{ 1, 3, 2, 7, 4 };
CycleSwap.cycleSwap(array);
System.out.println(Arrays.toString(array));
Output:
[4, 1, 3, 2, 7]
Code Sample:
int[] array = new int[]{ 1, 3, 2, 7, 4 };
CycleSwap.cycleSwap(array, 2);
System.out.println(Arrays.toString(array));
Output:
[7, 4, 1, 3, 2]
Code Sample:
int[] array = new int[]{ 1, 3, 2, 7, 4 };
CycleSwap.cycleSwap(array, 5);
System.out.println(Arrays.toString(array));
Output:
[1, 3, 2, 7, 4]
My code is:
<pre>class CycleSwap {
static void cycleSwap(int[] array) {
int shift = 1;
reverse(array, 0, array.length - 1);
reverse(array, shift, array.length - 1);
}
static void cycleSwap(int[] array, int shift) {
reverse(array, 0, array.length - 1);
reverse(array, 0, shift - 1);
reverse(array, shift, array.length - 1);
}
private static void reverse(int[] nums, int i, int j) {
while (i < j) {
int temp = nums[i];
nums[i] = nums[j];
nums[j] = temp;
i++;
j--;
}
}
public static void main(String[] args) {
{
int[] array = new int[]{1, 3, 2, 7, 4};
CycleSwap.cycleSwap(array,2);
System.out.println(Arrays.toString(array));
}
{
int[] array = new int[]{};
CycleSwap.cycleSwap(array);
System.out.println(Arrays.toString(array));
}
{
int[] array = new int[]{};
CycleSwap.cycleSwap(array, 3);
System.out.println(Arrays.toString(array));
}
}
}
Output:
[7, 4, 1, 3, 2]
[]
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
at com.epam.rd.autotasks.CycleSwap.reverse(CycleSwap.java:22)
at com.epam.rd.autotasks.CycleSwap.cycleSwap(CycleSwap.java:16)
at com.epam.rd.autotasks.CycleSwap.main(CycleSwap.java:43)
Do you know what is the problem?
|
|
|
|
|
Why are you trying to access elements of an empty array? But either way you can use the length property of the array to test whether it is empty or not.
|
|
|
|
|
"
Why are you trying to access elements of an empty array? "
Because is in the statement description. I have some failed tests and I thought maybe because of that.
Note that input array may be empty.
I tried like this, but still it's not working.
<pre>class CycleSwap {
static void cycleSwap(int[] array) {
int shift = 1;
reverse(array, 0, array.length - 1);
reverse(array, shift, array.length - 1);
}
static void cycleSwap(int[] array, int shift) {
reverse(array, 0, array.length - 1);
reverse(array, 0, shift - 1);
reverse(array, shift, array.length - 1);
}
private static void reverse(int[] nums, int i, int j) {
while (i < j) {
int temp = nums[i];
nums[i] = nums[j];
nums[j] = temp;
i++;
j--;
}
}
public static void main(String[] args) {
{
int[] array = new int[]{};
if (array.length == 0) {
System.out.println(0);
} else {
CycleSwap.cycleSwap(array, 2);
System.out.println(Arrays.toString(array));
}
}
}
}
I get this result:
[ERROR] CycleSwapTest.testCycleSwapEmptyCaseShift:44 � ArrayIndexOutOfBounds Index 0 o...
How can I fix that?
|
|
|
|
|
Probably because your test for zero length is in the wrong place. You need to test it at the beginning of each of the methods cycleSwap and reverse , since those are the places where the error can occur.
|
|
|
|
|
Yeah! You're right! I don't know why I didn't think about that!
|
|
|
|
|
Hello. I'm modifying the code below for my project. I just need help in Address Book GUI wherein:
1. I need to add "Enter Email Address" input in Add Record Button and
2. I need to insert another button, which is "Update Record" wherein I need to Update any existing records by typing his/her name and edit the the records of it including his/her name.
When I'm trying to modify this, I usually get an error in the codes. Please help me in this code. Thanks. No SQL Database needed and I'm using Apache Netbeans in here.
Link of my code:
https://drive.google.com/drive/folders/17PhFr3QYgiCQ8Z5tDcmZWxjbawvCGmY4?
|
|
|
|
|
If you have problems in your code then please edit your question above, and add complete details of what is not working.
|
|
|
|
|
Very few people are going to follow a link to an offsite google drive. Post the relevant code here in your post and give full details of the error, including which line it is thrown from
|
|
|
|
|
i am trying develop an algorithm to solve a Travelling Salesman Problem similar case where the goal is to find the best route with the highest attractiveness score (sum of scores for all visited sites/nodes) within a fixed time frame.
to illustrate this more:
a tourist wants to visit N attraction sites in a city and he only has 8 hours to visit as many attraction sites as possible. every site has an attractiveness score and the time spent to visit it.
example:
- site A with ID 0 has an attractiveness score of 90 and requires 10 minutes to visit it ([0, 90, 10])
- site B with ID 1 has an attractiveness score of 69 and requires 7 minutes to visit it ([1, 69, 7])
- site C with ID 2 has an attractiveness score of 72 and requires 7 minutes to visit it ([2, 72, 11])
- site D with ID 3 has an attractiveness score of 116 and requires 16 minutes to visit it ([3, 116, 16])
.
.
.
and so on.
Now we have a time matrix T where T[i][j] represents the necessary time to go from site i to site j. finally we consider site 0 as both the start site and the end site, i.e. the tourist starts his journey at site 0 and returns to site 0 (a hotel for instance).
so the task is to find an itinerary for the tourist to visit as many attractions as possible with a maximum sum score of attractiveness.
example of T matrix for sites A,B,C and D (it could be 50 sites):
T = [0, 40, 35, 90]
[30, 0, 25, 130]
[67, 83, 0, 75]
[45, 79, 130, 0]
The TSP has been solved using different algorithms or methods but i am stuck with this one as it's a little bit different in the sense that the goal is to find the maximum attractiveness score for an itinerary within a time frame, and not the shortest route.
your help is much appreciated
I thought of methods like greedy algorithm, dynamic programming used in TSP but couldn't find a way to solve this particular problem.
|
|
|
|
|
Hi. Is there a build-in function like in C# to scroll the child into viewport of ScrollPane ?
If not, how to achieve that using setVvalue() method of ScrollPane ?
I use below method to scroll, but it scrolls every control to the top of the viewport, but I want to scroll controls which are in the bottom of viewport to the bottom.
Bounds bounds = scrollPane.getViewportBounds();
scrollPane.setVvalue(flowPane.getChildren().get(3).getLayoutY() * (1/(flowPane.getHeight()-bounds.getHeight())));
|
|
|
|
|
Be careful of integer arithmetic.
1/(anything except 1) will yield 0.
Use more intermediate variables with precise names to help you via debugger.
|
|
|
|
|