-1
I have a problem about DATE. This giving error on line 58 about: Exception in thread "main" java.text.Parseexception: Unparseable date: "" at java.text.Dateformat.parse(Dateformat.java:366) exsecao14a.Exsecao14a.main(Exsecao14a.java:58) C: Users pedro Appdata Local Netbeans Cache 8.2rc executor-snippets run.xml:53: Java returned: 1 CONSTRUCTION FAILURE (total time: 14 seconds)
public static void main(String[] args) throws ParseException {
Scanner dados = new Scanner(System.in);
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
List<Product> pdc = new ArrayList<>();
System.out.print("Entre com o numero de produto: ");
int numeroP = dados.nextInt();
for (int i = 1; i <= numeroP; i++) {
System.out.println("Produto #" + i + " Data:");
System.out.print("Comum, usado ou importado (c/u/i)? ");
char cui = dados.next().charAt(0);
System.out.print("Nome: ");
dados.next();
String nome = dados.nextLine();
System.out.print("Preco: ");
double preco = dados.nextDouble();
if (cui == 'i') {
System.out.println("Taxa alfandega: ");
double taxa = dados.nextDouble();
pdc.add(new ImportedProduct(taxa, nome, preco));
} else if (cui == 'u') {
System.out.print("Data de fabricação: dd/mm/yyyy: ");
dados.next();
String formatoNormal = dados.nextLine();
Date formato = sdf.parse(formatoNormal); // ESSA É A LINHA 58
pdc.add(new UsedProduct(formato, nome, preco));
} else if (cui == 'c') {
pdc.add(new Product(nome, preco));
}
}
}
What happens if you remove the line "data.next();", two lines before line 58?
– João Victor Sierra
data Exception in thread "main" java.text.Parseexception: Unparseable date: "" Manufacturing date: dd/mm/yyyy: at java.text.Dateformat.parse(Dateformat.java:366) at exsecao14a.main(Exsecao14a.java:58) @Joãovictorsierra
– Pedro
It "skips" the line where you scan the formatNormal right? what I imagine is that it is consuming a enter that has been hung in some of the other readings of the scanner, the string will be empty and consequently an empty string when trying to be parsed from Exception
– Lucas Miranda
System.out.print("Manufacturing date: dd/mm/yyyy: "); Date format = sdf.parse(data.next());
– Pedro