Java - AYUDA (JAVA): ERROR Double.parseDouble

 
Vista:
sin imagen de perfil
Val: 11
Ha aumentado su posición en 3 puestos en Java (en relación al último mes)
Gráfica de Java

AYUDA (JAVA): ERROR Double.parseDouble

Publicado por fran (6 intervenciones) el 21/05/2020 13:56:01
Buenas amigos del foro, estoy teniendo problemas con el proyecto adjunto, al pulsar sobre la opción comprar, me da el siguiente error:

Estado HTTP 500 – Internal Server Error


Tipo Informe de Excepción

Descripción El servidor encontró un error interno que hizo que no pudiera rellenar este requerimiento.

excepción
java.lang.NullPointerException
sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1838)
sun.misc.FloatingDecimal.parseDouble(FloatingDecimal.java:110)
java.lang.Double.parseDouble(Double.java:538)
modelo.GestionVentas.service(GestionVentas.java:39)
javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)


nota La traza completa de la causa de este error se encuentra en los archivos de registro del servidor.



A ver si me pudieran ayudar. Muchas gracias
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de Billy Joel
Val: 2.665
Oro
Ha mantenido su posición en Java (en relación al último mes)
Gráfica de Java

AYUDA (JAVA): ERROR Double.parseDouble

Publicado por Billy Joel (878 intervenciones) el 21/05/2020 16:06:12
Lo que puedo ver es que en la línea 39 de tu clase GestionVentas tienes esto:
1
double e = Double.parseDouble(precio);

Es posible que el parámetro precio no esté llegando.
Te recomiendo verificar quien invoca tu servlet y cuales son los parámetros que le envía.

PD: Estuve revisando y parece que lo invocas a través de un link en el jsp libros.jsp. Los parámetros que le llega al Servlet son opcion y id. En otras palabras no llegan titulo, autor ni precio.

Se me ocurre agregar los parámetros que faltan al link:
1
<a href="GestionVentas?opcion=comprar&id=${i.index}&titulo=${lista.titulo}&autor=${lista.autor}&precio=${lista.precio}"><input type="submit" value="Comprar"/></a>

Cualquier duda solo pregunta.
Saludos,
Billy Joel
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar
sin imagen de perfil
Val: 11
Ha aumentado su posición en 3 puestos en Java (en relación al último mes)
Gráfica de Java

AYUDA (JAVA): ERROR Double.parseDouble

Publicado por fran (6 intervenciones) el 21/05/2020 16:55:52
Buenas, ante todo muchas gracias por la ayuda.

No me explique muy bien antes la verdad. La primera tabla si que se me genera con el título, autor y precio. El fallo me da al querer recuperar los libros en los que seleccioné la opción comprar en una segunda tabla.
TABLA

--------------------------------------------------------------------------------------------------
GestionVentas.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package modelo;
 
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
 
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
 
 
import beans.Libro;
 
@WebServlet("/GestionVentas")
public class GestionVentas extends HttpServlet {
	private static final long serialVersionUID = 1L;
 
    public GestionVentas() {
        super();
    }
 
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
 
		List<Libro> lista = null;
		HttpSession misesion = request.getSession();
		lista= (ArrayList<Libro>)misesion.getAttribute("lista");
		if (lista == null)
				lista= new ArrayList<Libro>();
		switch(request.getParameter("opcion")) {
 
		case "comprar":
			String titulo = request.getParameter("titulo");
			String autor = request.getParameter("autor");
			String precio = request.getParameter("precio");
 
			double e = Double.parseDouble(precio);
 
			Libro l = new Libro(titulo, autor, e);
			lista.add(l);
			misesion.setAttribute("lista", lista);
			request.getRequestDispatcher("libros.jsp").forward(request, response);
			break;
 
 
		case "eliminar":
			lista.remove(Integer.parseInt(request.getParameter("id")));
			misesion.setAttribute("lista", lista);
			request.getRequestDispatcher("libros.jsp").forward(request, response);
 
			break;
 
		}
	}
}
--------------------------------------------------------------------------------------------------

libros.jsp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<%@page import="beans.Libro"%>
<%@page import="java.util.ArrayList"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
 
<!DOCTYPE HTML>
<html>
<head>
<title>libros</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>
<body>
<h1>Listado de libros</h1>
 
<table border="1">
    <tr><th></th><th>Titulo</th><th>Autor</th><th>Precio</th></tr>
        <c:forEach items="${requestScope.libros}" var="lista" varStatus="i">
		<tr>
			<td><a href="GestionVentas?opcion=comprar&id=${i.index}">
              <input type="submit" value="Comprar"/></a></td>
			<td>${lista.titulo}</td>
			<td>${lista.autor}</td>
			<td>${lista.precio}</td>
		</tr>
		</c:forEach>
</table>
<br/><br/>
<br/><br/>
<table border=1 cellspacing=1 cellpadding=7 bordercolor="black">
		<tr><th></th><th>Titulo</th><th>Autor</th><th>Precio</th></tr>
		<c:forEach items="${applicationScope.libros}" var="libro" varStatus="i">
 
		<tr>
			<td><a href="GestionVentas?opcion=eliminar&id=${i.index}">
              <input type="submit" value="eliminar"/></a></td>
			<td><c:out value="${libro.titulo}"></c:out></td>
			<td><c:out value="${libro.autor}"></c:out></td>
			<td><c:out value="${libro.precio}"></c:out></td>
		</tr>
		</c:forEach>
	</table>
 
<a href="Controller?op=doTemas">Otro tema</a>
<br/><br/>
</body>
</html>


Muchas gracias,
Saludos
Fran Castu
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar