-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Task Two New Line error #10
Comments
It looks like transactionline from this loop in the test: for (String transactionLine : transactionLines){ is printing out the whole data file as a string, rather than separating each line |
Make sure that you're properly handling newlines and commas and that the data is split correctly for processing. |
for (String transactionLine : transactionLines) {
} |
This comment has been minimized.
This comment has been minimized.
The provided code snippet seems to be part of a Java program that processes a string split into parts. However, there are a couple of issues that need to be addressed. Here is a revised version of the code: // Check if there are exactly two parts
if (parts.length == 2) {
try {
double value1 = Double.parseDouble(parts[0].trim());
double value2 = Double.parseDouble(parts[1].trim());
// Create the transaction line (assuming you want to format it somehow)
String transactionLine = value1 + "," + value2; // Adjust according to your needs
// Process the values (e.g., sending them to the producer)
kafkaProducer.send(transactionLine);
} catch (NumberFormatException e) {
System.out.println("Invalid number format: " + transactionLine);
}
} else {
System.out.println("Unexpected data format: " + transactionLine);
} Key Changes:
This should resolve any issues with the code snippet provided. |
I am receiving the following error in the TaskTwoTests file even before I try implementing a listener specifically with "kafkaProducer.send(transactionLine);":
"java.lang.NumberFormatException: For input string: "122.86
5"
at java.base/jdk.internal.math.FloatingDecimal.readJavaFormatString([FloatingDecimal.java:2054](..."
The data file this is using has 122.86 and 5 separated by a new line character. It had no issues processing the numbers beforehand separated by a comma. The yaml file was actually blank when I downloaded the zip so a used the solution provided in the other post (Thank you for that). Am I meant to fix this somehow in my listener class, or could there be an error in my configuration files? I am running VS Code on Windows 11.
The text was updated successfully, but these errors were encountered: